问题:产生一组(四个)随机数。
要求:每组随机数随机生成数字、字母(分大小写)。
代码:
<span style="white-space:pre"> </span>char vercode[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','G','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};//定义随机数字符
int length = sizeof(vercode)/sizeof(char);//计算数组长度
int one = arc4random() % length;//定义四个随机数
int two = arc4random() % length;
int three = arc4random() % length;
int four = arc4random() %length;
NSLog(@"验证码:%c %c %c %c",vercode[one],vercode[two],vercode[three],vercode[four]);//利用数组下标赋值