有个项目要给客户发送随机验证码, 试了下这样可以 srand(time(0)); code = [NSString stringWithFormat:@"%d", (rand() % (9999 - 1001)) + 1001];