Random numbers generated using uniform real distribution in C++ are not really uniformly distributed -


i wrote small code make sure can random numbers wide range, ex. [0, 10^36) because going use these wide ranges later.

my code follows:

#include <iostream> #include <cmath> #include <random> #include <chrono>  int main() {   unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();     double expo = pow(10,36);     std::uniform_real_distribution<double> dist(0,expo);     std::mt19937_64 rng(seed);     (int i=0; i<10; i++)         std::cout << dist(rng) << std::endl;     return 0; }    

and following example of output:

6.75507e+035 4.01129e+035 6.85525e+035 8.85896e+035 3.1455e+035 3.04962e+035 5.48817e+035 3.54502e+035 2.24337e+035 2.23367e+035 

as can see, random numbers close upper endpoint of given interval. tried running program lots of times, increased 10 numbers 100, random numbers close upper endpoint of interval (with exponent 35, , 34).

since have used std::uniform_real_distribution, expect have , numbers in range [0, 1000] example. not find uniform distribution. important me random number not close upper endpoint because going use random number later in if-statement:

if (random_number == 0)     //do operations 

and upper endpoint used rate, in occurs. seems random number has no chance 0 sometimes.

i not know why happens , appreciate idea or help.

(eclipse 4.4.1, windows 7)

as can see, random numbers close upper endpoint of given interval.

no, they're not. one, example:

2.23367e+035 

note in range [0, 1e36], sub-range [1e35, 1e36] 9 times large sub-range [0, 1e35], uniform distribution, can expect see numbers 9 times often. see numbers exponent of 34 , then, exponents lower exceedingly rare.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -