![]() |
|
Random Numbers - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: Random Numbers (/showthread.php?tid=3890) Pages:
1
2
|
Random Numbers - PhilOfPerth - 08-25-2025 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 pointRE: Random Numbers - SMcNeill - 08-25-2025 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. RE: Random Numbers - PhilOfPerth - 08-25-2025 (08-25-2025, 12:12 AM)SMcNeill Wrote: https://qb64phoenix.com/forum/showthread.php?tid=3644 <-- Our formulas for RND. 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. RE: Random Numbers - JRace - 08-25-2025 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.) RE: Random Numbers - PhilOfPerth - 08-25-2025 (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. 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. RE: Random Numbers - Pete - 08-27-2025 I had a new perspective once, but my old perspective got better mileage. Pete
RE: Random Numbers - SMcNeill - 08-27-2025 (08-27-2025, 09:43 PM)Pete Wrote: I had a new perspective once, but my old perspective got better mileage. 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! RE: Random Numbers - Pete - 08-27-2025 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 RE: Random Numbers - madscijr - 08-28-2025 That pseudo-3D chart is a neat way to visualize the randomness. Well done! RE: Random Numbers - Herve - 08-28-2025 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. |