Skip to content

Random number generation - merging bot articles#79

Open
ProfessionalMenace wants to merge 5 commits into
TCCPP:mainfrom
ProfessionalMenace:random
Open

Random number generation - merging bot articles#79
ProfessionalMenace wants to merge 5 commits into
TCCPP:mainfrom
ProfessionalMenace:random

Conversation

@ProfessionalMenace

Copy link
Copy Markdown
Contributor

#69

  • migrated bot article
  • expanded content

@jeremy-rifkin jeremy-rifkin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread wiki/cpp-tutorial/random.md Outdated
Comment thread wiki/cpp-tutorial/random.md Outdated
Comment thread wiki/cpp-tutorial/random.md Outdated
Comment thread wiki/cpp-tutorial/random.md Outdated
Comment thread wiki/cpp-tutorial/random.md Outdated
Comment thread wiki/cpp-tutorial/random.md
ProfessionalMenace and others added 2 commits February 27, 2026 20:57
Co-authored-by: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com>

@jeremy-rifkin jeremy-rifkin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread wiki/cpp-tutorial/sidebar.ts Outdated
Comment thread wiki/cpp-tutorial/random.md Outdated
Comment thread wiki/cpp-tutorial/random.md
Comment thread wiki/cpp-tutorial/random.md Outdated
Comment on lines +44 to +47
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread wiki/cpp-tutorial/random.md
Comment thread wiki/cpp-tutorial/random.md Outdated
## 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to talk about the range

Comment thread wiki/cpp-tutorial/random.md Outdated
Comment thread wiki/cpp-tutorial/random.md
@ProfessionalMenace

Copy link
Copy Markdown
Contributor Author

Sorry for taking so much time. I'll try getting back to this soon

ProfessionalMenace and others added 2 commits June 15, 2026 14:54
Co-authored-by: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants