So ur saying that everytime i call distribution (generator) it makes a new random number |
Yes. In the range you chose when creating the distribution. 1 to 10, inclusive, line 12.
You want someone to guess a SINGLE random number, you generate one. Line 19.
You get the guess from the user, line 16, and compare the stored random number with the user input.
A game of Heads/Tails, each guess you flip the coin ONCE. Possible distribution of (0, 1).
distribution(generator)
as you set up in your program is CRUDELY similar to
rand() % 10 + 1
.
generator()
gets a new random number,
distribution()
modifies the random number to conform to the specified distribution range. With a uniform distribution any number in the range has the same chance of being generated as every other number.
rand()
has bias issues, as explained here:
http://www.cplusplus.com/forum/beginner/251741/#msg1108315
There are other distributions available in the
<random>
header, that generates numbers by other means. One,
std::normal_distribution
can generate random numbers on a bell curve.
Generating random numbers with C++ can be intimidating at first because there are so many options. And is done differently than how random numbers are generated in C.