這些都是本人從網站上找來的,總結在一起,大家一起學習吧!
1、使用26個英文字母隨機產生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、產生隨機數字
(1)、?獲取一個隨機整數范圍在:[0,100)包括0,不包括100
int x =arc4random() % 100;
(2)、??獲取一個隨機數范圍在:[500,1000),包括500,不包括1000
int y =(arc4random() % 501) + 500;
(3)、??獲取一個隨機整數,范圍在[from,to),包括from,不包括to
-(int)getRandomNumber:(int)from to:(int)to
{
return (int)(from + (arc4random() % (to – from +1)));
}
(小數)doubleval = ((double)arc4random() /0x100000000);
數字轉換成字符串
objective c將整型轉換為字符型:
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];