29 Numerics library [numerics]

29.5 Random number generation [rand]

29.5.8 Utilities [rand.util]

29.5.8.2 Function template generate_canonical [rand.util.canonical]

template<class RealType, size_t digits, class URBG> RealType generate_canonical(URBG& g);
Let
  • r be numeric_limits<RealType>​::​radix,
  • R be
  • d be the smaller of digits and numeric_limits<RealType>​::​digits,237
  • k be the smallest integer such that
  • x be
An attempt is k invocations of g() to obtain values
Returns:
[Note 2: 
The return value c satisfies
— end note]
[Note 3: 
If the values
Obtaining a value in this way can be a useful step in the process of transforming a value generated by a uniform random bit generator into a value that can be delivered by a random number distribution.
— end note]
[Note 4: 
When R is a power of r, an implementation can avoid using an arithmetic type that is wider than the output when computing S.
— end note]
237)237)
d is introduced to avoid any attempt to produce more bits of randomness than can be held in RealType.

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant