what is the meaning of "all engines produce integer numbers in a uniform distribution"?

This can't mean the probability of an engine to produce a value in a range is the same for each value, because then we would not have a normal distribution when using normal_distribution. So what is referred as all engines produce uniform distributions seems contradictory to me...


Sorry some math deficiency there...

Regards,
Juan
C++ separates the concept of a "generator" from a "distribution".
http://www.cplusplus.com/reference/random/

The above link shows a list of random number generators in C++. As far as I know, yes they all produce integer numbers in a uniform distribution.

Distributions (also shown on that page) are what you use to get normal distributions, [a, b] uniform distributions, poisson distribution, etc. A distribution uses a generator to produce a random number.

For example, std::mt19937 is a generator.
Calling the following will produce a random number:
1
2
  std::mt19937 generator (seed);  // mt19937 is a standard mersenne_twister_engine
  std::cout << "Random value: " << generator() << '\n';


But if you want to actually get a random number from a distribution, you have to call my_distribution(generator);
Last edited on
if you think about it, that is the most reusable way. any generator can work with any distribution if the distribution knows what is coming in (uniform values). If the generators all did their own thing, making them fit a distribution would be quite challenging, eg if it needed to convert the generator's beta to a chi-squared...
All of the C++ <random> random number engines satisfy the C++ standard requirement for being a random number bit generator, a function object returning unsigned integer values such that each value in the range of possible results has (ideally) equal probability.

https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerator

The engines are not intended to be used directly as psuedo-random number generators (PRNGs)*, they are used to supply bits to a random number distribution object to generate random numbers.

You could use rand() by itself, but a distribution clamp is more often used to generate random numbers in a given range (a distribution):

int num = rand() % RANGE + STARTING_PLACE;

The C-library -- srand()/rand() -- is not a good random generator. Even the C standard recommends not using it.

https://web.archive.org/web/20180123103235/http://cpp.indi.frih.net/blog/2014/12/the-bell-has-tolled-for-rand/

Instead of just one random generator C++ has several pre-defined engines. Along with several adaptors that modify how the pseudo-random numbers are generated.

The C++ <random> library also has several distributions pre-defined, including the ability to generate random floating point numbers. The C-library can't do that.

*<random> has one engine that can be used directly to generate random numbers: std::random_device. It is not recommended for generating more than a handful of random numbers, such as serving as a seed for the PRNG engines.
* but there is absolutely no reason why you couldn't.

i.e. the recommendation is wrong.
Last edited on
Topic archived. No new replies allowed.