chess:programming:prng_pseudo_random_number_generator:a_pseudo_random_number_generator_using_srand
Chess - Programming - PRNG (Pseudo Random Number Generator) - A Pseudo Random Number Generator using srand()
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { srand(time(NULL)); int i; for(i = 0; i<5; i++) printf("%d ", rand()%10); }
returns:
3 7 0 9 8
NOTE: srand() sets the seed which is used by rand() to generate random numbers.
- time(NULL) return number of second from JAN 1, 1971.
- This means every time the program is run the results will differ as the program will get a new seed.
chess/programming/prng_pseudo_random_number_generator/a_pseudo_random_number_generator_using_srand.txt · Last modified: 2021/10/31 19:20 by peter