This website introduces a lot of
Http://stackoverflow.com/questions/17598547/why-is-the-first-result-of-rand-doublerand-max-is-not-random
and
http://stackoverflow.com/questions/1340729/ How-do-you-generate-a-random-double-uniformly-distributed-between-0-and-1-from-c
Range is 0-1
Double x= (double) rand ()/(double) rand_max);
1#include <iostream>2#include <iomanip>3#include <map>4#include <random>5 6 intMain ()7 {8 Std::random_device Rd;9 Ten One std::mt19937 E2 (RD ()); A -Std::uniform_real_distribution<> Dist (0,1); - thestd::map<int,int>hist; - for(intn =0; N <10000; ++N) { -++Hist[std::round (Dist (E2))]; - } + - for(Auto p:hist) { +Std::cout << std::fixed<< Std::setprecision (1) << STD::SETW (2) A<< P.first <<' '<< std::string(p.second/ $,'*') <<'\ n'; at } -}
Range is 0-1
1 #include <stdlib.h>23double randzerotoone ()4{ 5 return1.); 6 }
Range is m to n
double Randmton (doubledouble N) { return M + (rand ()/( Rand_max/(n-M)); }
Get a random number from 0 to 1