Current location - Training Enrollment Network - Mathematics courses - What is a random function? How to define it? How to use it?
What is a random function? How to define it? How to use it?
Random functions are functions that generate numbers, and there are rand (), srand () and other functions in C language.

Usage is as follows:

# include & ltstdlib.h & gt

# include & ltstdio.h & gt

# include & lttime.h & gt

Invalid master (invalid)

{

int i,k;

Srand ((unsigned) time (empty)); //Initialize a random function with the system time as the seed.

for(I = 0; I< 10; i++)

{

k = rand()% 100; //Generate each random number

printf( " k=%d\n ",k);

}

}