c语言随机数函数示例
本文导语: void srand( unsigned int seed );head file is RemarksThe srand function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point. rand retrieves the pse...
void srand( unsigned int seed );
head file is
Remarks
The srand function sets the starting point for generating a series of pseudorandom
integers. To reinitialize the generator, use 1 as the seed argument. Any other value for
seed sets the generator to a random starting point. rand retrieves the pseudorandom
numbers that are generated. Calling rand before any call to srand generates the same
sequence as calling srand with seed passed as 1.
#include
#include
#include
void main( void )
{
int i;
/* 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++ )
printf(" %6dn", rand());
}