Posts: 799
Threads: 140
Joined: Apr 2022
Reputation:
33
I was curious to know how many random numbers were generated
by the Randomize function, so I wrote this short prog:
Code: (Select All) 'set start point
DefLng C: DefDbl F, L, D
startat = Int(Rnd * 1000) ' set random Start point in the "list"
For a = 1 To startat: n = Rnd: Next ' generate each random number in turn
First = Rnd: Print First ' set this random number as start point
While First <> last ' wait for the next time this number is found
count = count + 1
last = Rnd ' read each random number
Print count; last; " "; ' show random number and how many random numbere were read
Wend
{I found it interesting, anyway!)
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) 
Please visit my Website at: http://oldendayskids.blogspot.com/
Posts: 3,446
Threads: 376
Joined: Apr 2022
Reputation:
345
https://qb64phoenix.com/forum/showthread.php?tid=3644 <-- Our formulas for RND.
The answer you're looking for here is in the MOD. It's 2 ^ 24, or 16,777,216. That's the max number of random numbers we generate before repeating the cycle over again.
Posts: 799
Threads: 140
Joined: Apr 2022
Reputation:
33
(08-25-2025, 12:12 AM)SMcNeill Wrote: https://qb64phoenix.com/forum/showthread.php?tid=3644 <-- Our formulas for RND.
The answer you're looking for here is in the MOD. It's 2 ^ 24, or 16,777,216. That's the max number of random numbers we generate before repeating the cycle over again.
That's the same result as is produced by my prog (plus 1).
I hadn't seen that Mod, so thanks. I got a new perspective
though, and I achieved what I wanted.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) 
Please visit my Website at: http://oldendayskids.blogspot.com/
Posts: 213
Threads: 5
Joined: Apr 2022
Reputation:
27
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.)
Posts: 799
Threads: 140
Joined: Apr 2022
Reputation:
33
(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.) 
Please visit my Website at: http://oldendayskids.blogspot.com/
Posts: 2,910
Threads: 305
Joined: Apr 2022
Reputation:
167
I had a new perspective once, but my old perspective got better mileage.
Pete
Posts: 3,446
Threads: 376
Joined: Apr 2022
Reputation:
345
(08-27-2025, 09:43 PM)Pete Wrote: I had a new perspective once, but my old perspective got better mileage.
Pete 
Sounds like my damn new electric tractor. Thing doesn't get ANY mileage no matter how much gas I pour on it. It just sits there and burns!
Posts: 2,910
Threads: 305
Joined: Apr 2022
Reputation:
167
I really wonder how much good we are getting out of this go green garbage. I mean I paid good money for my solar powered night vision goggles, but I'm still getting my ass kicked at midnight paintball! I knew I should have bought the gasoline powered ones!
Pete
Posts: 1,215
Threads: 162
Joined: Apr 2022
Reputation:
34
That pseudo-3D chart is a neat way to visualize the randomness. Well done!
Posts: 41
Threads: 8
Joined: Jul 2025
Reputation:
7
Hi,
A few years ago, I needed to obtain a long series of truly randomized numbers; I used the tools offered by https://random.org. If you are not familiar with it, I encourage you to rush to their site.
|