lundi 3 septembre 2018

How to use srand to make a random number generator?

I have this bit of code from a larger chunk, and I need to edit it so I can randomly generate numbers that are different from each other. Right now, the same numbers keep appearing in a row each time I run it in the terminal (934 then 744 etc.)

int main(void)
{
// srand( time( 0 ) ); // seed random number generator
 guessGame();
} // end main

More specifically, I think need to edit the

srand(time( 0 ) );

part.

How can I do that in order to make the numbers generate randomly every time, and not the same few every time I run the program?




Aucun commentaire:

Enregistrer un commentaire