Random number generation - merging bot articles#79
Conversation
jeremy-rifkin
left a comment
There was a problem hiding this comment.
Thanks for taking the time to write this! I have given it a quick look and left some comments below.
This is a very in-depth article on random number generators. If this is going to be put in cpp-tutorial, it should be much more beginner focused. I would recommend splitting this page in two: A beginner introduction in cpp-tutorial and a RNG deep-dive somewhere in the resources section.
jeremy-rifkin
left a comment
There was a problem hiding this comment.
Thanks for the changes! I've left some more comments below. The main structural issue from before still stands: This is too much of a deep-dive into random number generation for a tutorial article. There is a lot of great information here which would be great to have in the resources section of the wiki. I would say LCG, seed_seq, predefined generators table, and philox all belong in a resources page. For the beginner article, just focusing on rand(), a random engine, a random device, std::default_random_engine/std::mt19937, and the three most important distributions should be good. Then linking to the resource page for more in-depth information would be perfect.
| Unlike the C `rand()` function, which relies on common shared seed via `srand()`, the C++ random engines are independent | ||
| and each one has its own seed. This ensures thread safety, whereas C `rand()` does not. Another thing worth mentioning | ||
| about `rand()` is that it is implementation defined and can vary system to system. The C++ random library should be | ||
| always preferred. |
There was a problem hiding this comment.
This doesn't really capture why rand() is bad. Yes, it is implementation-defined and global, but the most important practical reason is poor randomness quality in all major implementations. rand() % n being biased could also be mentioned.
| ## Seed Sequence | ||
|
|
||
| Seed sequence (`std::seed_seq`) is an utility in the standard library for converting a small number of inputs into a | ||
| higher quality seed (does not contain large areas of zeros/ones) suitable for seeding PRNGs with large internal state |
There was a problem hiding this comment.
I don't think "does not contain large areas of zeros/ones" is really useful for beginners. It isn't really accurate to say it creates a "higher quality seed" as it can't magically increase entropy, but the mixing it does can improve distribution / bias.
| // initialize a uniform real distribution | ||
| std::uniform_real_distribution<double> dis{0.0, 1.0}; | ||
|
|
||
| // generate random numbers in the interval [0, 1) |
There was a problem hiding this comment.
Might be good to talk about the range
|
Sorry for taking so much time. I'll try getting back to this soon |
Co-authored-by: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com>
#69