这是我的代码:
-(void)randommoves
{
NSArray *possiblemoves =[NSArray arrayWithObjects:@"R ",@"R' ",@"L ",@"L' ",@"B ",@"B' ",@"F ",@"F' ",@"U ",@"U' ",@"D ",@"D' ", nil];
NSMutableString *finalmoves = [[NSMutableString alloc] init];
finalmoves = [NSMutableString stringWithCapacity:0];
[finalmoves retain];
int i = 0;
for (i=0; i<20; i++) {
int r = rand() % 13;
NSString *string = [possiblemoves objectAtIndex:r];
[finalmoves appendString:string];
}
NSLog(@"%@",finalmoves);
[finalmoves release];
}
每次我运行它时,我都会得到完全相同的字符串 "D' B B' D L' D' F' L' B' U' DD D' L' URBF D' B' "
我想要它做的是每次运行它时给我一个新的动作集
我已经运行了至少 30 次,以确保它不是侥幸,并且它确实返回了相同的字符串,而且确实如此。