08-25-2025, 07:05 PM
QB64 uses a Linear Congruential Generator (LCG), much like the generators used by older Basic interpreters & compilers.
The quality of an LCG's output is totally dependent on the parameters used by the generator.
Below is a pseudo-3D plot of QB64PE's RND output:
Notice how the purple points pretty much fill the volume of the displayed cube. As LCGs go, the one used by QB64PE seems to do a pretty decent job, although I don't know if it generates EVERY possible random number within its range.
BUT!
If an LCG's parameters are chosen poorly then the output WILL NOT generate every possible number, as shown in this plot of numbers generated by the notorious RANDU LGC:
RANDU's output falls on one of 15 planes. All of that whitespace in the image represents numbers that will NEVER be generated no matter how many times you call RANDU.
TLDR, QB64PE's RND function seems to be pretty respectable.
(Sorry I didn't use PE to create these images. Once upon a time I started a PE program to display side-by-side the outputs of different PseudoRandom Number Generators, but feature creep and limited time killed that project.)
The quality of an LCG's output is totally dependent on the parameters used by the generator.
Below is a pseudo-3D plot of QB64PE's RND output:
Notice how the purple points pretty much fill the volume of the displayed cube. As LCGs go, the one used by QB64PE seems to do a pretty decent job, although I don't know if it generates EVERY possible random number within its range.
BUT!
If an LCG's parameters are chosen poorly then the output WILL NOT generate every possible number, as shown in this plot of numbers generated by the notorious RANDU LGC:
RANDU's output falls on one of 15 planes. All of that whitespace in the image represents numbers that will NEVER be generated no matter how many times you call RANDU.
TLDR, QB64PE's RND function seems to be pretty respectable.
(Sorry I didn't use PE to create these images. Once upon a time I started a PE program to display side-by-side the outputs of different PseudoRandom Number Generators, but feature creep and limited time killed that project.)

