RAND ()
C++11:default_random_engine
- Basic: C++11 provides a new random number generator, a random number engine default_random_engine, which contains header files when used #include <random>;
- scope: By default, the build scope of the default_random_engine is a unsigned, which can be obtained from the method min () and Max () .
- seed: similar to rand (), Default_random_engine also needs to change the resulting sequence by a random number seed, which can be set by invoking the method seed ();
- distribution and floating point: the random number engine can set the build range by distributing objects,uniform_int_distribution<unsigned> or Uniform_real_distribution <double>;
- relative rand (), you can use uniform_real_distribution<> to generate random floating-point numbers, and without worrying about the accuracy problem, the random number engine is used as follows:
Default_random_engine e;//defining the random number engineUniform_int_distribution<unsigned> ID (1,Ten);//Integral type distributionuniform_real_distribution<Double> dd (0,1.0);//floating-point distributionE.seed (Ten);//set random number seed for(size_t i =0; I <Ten; i++) {cout<< ID (E) <<" ; "<< DD (e) <<Endl; }
"C + +" random number engine