In c + + to develop the generating random number with what function
CodePudding user response:
When using the rand () function, you first need to include the header file # include
, usage is int rand (void), produced by random number range is 0 to 65536, a type of unsigned int, cannot exceed the scope, the rand () function does not accept parameters, the default seed for 1) (i.e., the initial value, random number generator is always begin with the same seed, so the formation of pseudo random sequence is also same, lost the meaning of random, to be different, right now you need to use the function srand () to initialize,
Srand () function is used to initialize the random number generator, usage for the void srand (unsigned int) seed, seed parameters must be a integer, if every seed set the same value, the rand () generated by the random number every time will be the same,