The function srand () in C
The function void srand (unsigned int seed) provides seed for the random number generator used by the rand function.
The function void srand (unsigned int seed) provides seed for the random number generator used by the rand function.
Declaring the function srand () in C
Below is the declaration for srand () in C:
void srand ( unsigned int seed )
Parameters
seed : is an integer value, used as a seed by a random number algorithm.
Returns the value
This function does not return any values.
For example
The following C program illustrates the usage of srand () in C:
#include #include #include int main () { int i , n ; time_t t ; n = 5 ; /* Khoi tao bo sinh so ngau nhien */ srand (( unsigned ) time (& t )); /* in 5 so ngau nhien trong day tu 0 toi 50 */ for ( i = 0 ; i < n ; i ++ ) { printf ( "%dn" , rand () % 50 ); } return ( 0 ); }
Compiling and running the above C program will result:
According to Tutorialspoint
Previous article: Function rand () in C
Next lesson: Function mblen () in C
5 ★ | 1 Vote
You should read it
- Call the function by value in C ++
- Function in programming C
- Call the function by pointer in C ++
- Function putc () in C
- The function getc () in C
- Atof () function in C
- Function vfprintf () in C
- The function setvbuf () in C
- Function setbuf () in C
- The sprintf () function in C
- The ord () function in Python
- Remove () function in C