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
Discover more
parameter in CShare by
Micah Soto
Update 25 May 2019
You should read it
- 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 Quiet Details That Make a Sports Betting Platform Feel Reliable
- Instructions on creating toy set images with ChatGPT AI
- How are AI agents changing the journalism industry?
- The function mblen () in C
- The function mbstowcs () in C
- The function mbtowc () in C