随机数
直接上带代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #define _CRT_SECURE_NO_WARNINGS//关闭安全检查 2 # include<stdio.h> 3 # include<stdlib.h> 4 /* 5 伪随机数的生成 6 */ 7 int main1() 8 { 9 int seed = 0xffffffff,i; 10 srand((unsigned int)seed);//种子 11 for (i = 0; i < 5; i++) 12 printf("%d\t", rand() % 10);//生成0~9之间的数 13 printf("\n\n"); 14 system("pause"); 15 } 16 17 /* 18 用时间生成随机数 19 */ 20 21 int main2() 22 { 23 time_t ts; 24 srand((unsigned int)time(&ts)); 25 int num = rand()%100+1; 26 printf("%d", num); 27 getchar(); 28 29 } 30 31 /* 32 生成的结果不在意料之中,记录一下 33 */ 34 int main() 35 { 36 int seed, i; 37 for (;;) 38 { 39 printf("Please input a number to set the seed:"); 40 scanf("%d", &seed); 41 if (seed == 0) 42 break; 43 srand((unsigned int)seed); 44 for (i = 0; i < 5; i++) 45 printf("%d\t", rand()); 46 printf("\n\n"); 47 } 48 system("pause"); 49 }