這些都是本人從網(wǎng)站上找來的,總結(jié)在一起漂辐,大家一起學(xué)習(xí)吧泪喊!
1、使用26個(gè)英文字母隨機(jī)產(chǎn)生10位的字符串
int?NUMBER_OF_CHARS =10;
char?data[NUMBER_OF_CHARS];
for?(intx=0;xchar)('A'?+(arc4random_uniform(26))));
NSString?*dataPoint =[[NSString alloc]initWithBytes:data?length:NUMBER_OF_CHARSencoding:NSUTF8StringEncoding];
2髓涯、產(chǎn)生隨機(jī)數(shù)字
(1)窘俺、?獲取一個(gè)隨機(jī)整數(shù)范圍在:[0,100)包括0,不包括100
int x =arc4random() % 100;
(2)复凳、??獲取一個(gè)隨機(jī)數(shù)范圍在:[500,1000)瘤泪,包括500,不包括1000
int y =(arc4random() % 501) + 500;
(3)育八、??獲取一個(gè)隨機(jī)整數(shù)对途,范圍在[from,to),包括from髓棋,不包括to
-(int)getRandomNumber:(int)from to:(int)to
{
return (int)(from + (arc4random() % (to – from +1)));
}
(小數(shù))doubleval = ((double)arc4random() /0x100000000);
數(shù)字轉(zhuǎn)換成字符串
objective c將整型轉(zhuǎn)換為字符型:
Convert Integer to NSString:
int Value = 112;
NSString *ValueString = [NSString stringWithFormat:@"%d", Value];
Convert NSString to C Integer:
int Value = 112;
int ValueString = [ValueintValue];
char *ValueasCString = (char *)[ValueString UTF8String];