/* RAND.C: This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/#include <stdlib.h>
#include <stdio.h>
#include <time.h>void main( void )
{
int i;
int temp; /* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) ); /* Display 10 numbers. */
for( i = 0; i < 10;i++ )
{
temp = (rand()%5) + 1;
printf( " %d\n", temp);
}}
温馨提示:内容为网友见解,仅供参考