+ 3
how to use random in c language ?
5 Antworten
+ 14
srand is generate secured random number so use of this is quite good.
The function srand() is used to initialize the pseudo-random number generator by passing the argument seed. Often the function time is used as input for the seed. If the seed is set to 1 then the generator is reinitialized to its initial value. Then it will produce the results.
https://www.codingunit.com/c-reference-stdlib-h-function-srand-initialize-random-number-generator
srand(time(NULL));
int g = rand();
https://linux.die.net/man/3/random
https://stackoverflow.com/questions/822323/how-to-generate-a-random-int-in-c/39475626#39475626
+ 5
// use rand() function
+ 2
We can use random generator function provided in standard library i.e stdlib.h By srand()
+ 2
This code is not my original work but it is an example I looked up on Google
https://code.sololearn.com/cGtCk05HS7Cq/?ref=app