Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Numbers
#5
(08-25-2025, 07:05 PM)JRace Wrote: 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.)

Thanks, JRace. I believe my little prog (top of this thread) finds all possible results  (16777215) for our RND function. Yes, I guess that's respectable and suits most of our applications.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply


Messages In This Thread
Random Numbers - by PhilOfPerth - 08-25-2025, 12:04 AM
RE: Random Numbers - by SMcNeill - 08-25-2025, 12:12 AM
RE: Random Numbers - by PhilOfPerth - 08-25-2025, 01:04 AM
RE: Random Numbers - by JRace - 08-25-2025, 07:05 PM
RE: Random Numbers - by PhilOfPerth - 08-25-2025, 10:27 PM
RE: Random Numbers - by Pete - 08-27-2025, 09:43 PM
RE: Random Numbers - by SMcNeill - 08-27-2025, 10:05 PM
RE: Random Numbers - by Pete - 08-27-2025, 10:54 PM
RE: Random Numbers - by madscijr - 08-28-2025, 01:03 PM
RE: Random Numbers - by Herve - 08-28-2025, 07:06 PM
RE: Random Numbers - by madscijr - 08-30-2025, 12:19 AM
RE: Random Numbers - by Pete - 08-28-2025, 07:47 PM
RE: Random Numbers - by madscijr - 08-30-2025, 12:24 AM
RE: Random Numbers - by Magdha - 10-18-2025, 02:36 PM
RE: Random Numbers - by hsiangch_ong - 10-19-2025, 05:31 AM
RE: Random Numbers - by dano - 10-19-2025, 08:54 PM
RE: Random Numbers - by Pete - 10-19-2025, 10:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strings - Numbers Kernelpanic 0 112 01-20-2026, 10:29 PM
Last Post: Kernelpanic
  using pseudo-random numbers for repeatable content - kind of a neat trick madscijr 5 1,004 02-13-2025, 11:12 PM
Last Post: Pete
  random numbers badger 8 1,389 11-08-2024, 02:22 AM
Last Post: DANILIN
  Identifying colour attributes with negative numbers CharlieJV 1 575 01-28-2023, 05:16 AM
Last Post: CharlieJV
  Anybody use decimals for line numbers? Pete 6 1,110 08-05-2022, 03:28 AM
Last Post: bplus

Forum Jump:


Users browsing this thread: 1 Guest(s)