#include <stdlib.h>
#include<stdio.h>
#include<time.h>
#define randomize() srand((unsigned)time(NULL)) //定义一个宏
int main(void)
{
int i;
printf("Ten random numbers from 0 to 99/n/n");
randomize();
for(i=0; i<100; i++)
{
printf("%d/n", rand() % 100);
sleep(1);
}
return 0;
}
<运行>
root@farsight:/mnt/hgfs/E/yinhui/12.3/msg# gcc tttt.c -o tttt
root@farsight:/mnt/hgfs/E/yinhui/12.3/msg# ./tttt
Ten random numbers from 0 to 99
87
80
68
39
39
53
14
96
46