![]() |
RND and RANDOMIZE information - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Official Links (https://qb64phoenix.com/forum/forumdisplay.php?fid=16) +--- Forum: Learning Resources and Archives (https://qb64phoenix.com/forum/forumdisplay.php?fid=13) +--- Thread: RND and RANDOMIZE information (/showthread.php?tid=3644) |
RND and RANDOMIZE information - SMcNeill - 04-28-2025 I'd posted this information back at the old forums back in 2019 and I'd thought that I'd copied it over here for everyone, but I couldn't find it. Here is everything you ever wanted to know about RND and RANDOMIZE. First, a link to the original I posted: https://qb64forum.alephc.xyz/index.php?topic=1414.msg105988#msg105988 Then a quick copy of the info in case that site ever goes down for whatever reason: For folks who want a little extra information about how RND and RANDOMIZE work in QBASIC (and has been imitated to work the same in QB64), here's a little old documentation I dug up from the old drive on them: Code: (Select All) ;*** As you can see, we don't have any true randomness with RND in QB64. In fact, our results are calculated on a mathematical formula! (Which is why we always get the same results if we don't use RANDOMIZE TIMER to jump to some off point in the list of numbers we generate and use.) If you're interested in this stuff, then here it is. If not, then just ignore this topic and trust that RND isn't truly random -- which is why we call it pseduo-random, at best. ![]() And, after a little more digging, I discovered this is the truth for QB64's randomize: Apparently either the documentation I found is old and didn't apply to QBASIC RND (maybe it was the formula used with some other version Microsoft produced?), or else QB64 uses a different RND formula. What we actually use is this one (as taken from libqb.cpp): Code: (Select All) float func_rnd(float n,int32 passed){ Instead of a formula where Seed = (Seed * 214013 + 2531011) MOD 2 ^ 24, we use one where rnd_seed=(rnd_seed*16598013+12820163)&0xFFFFFF; Basically the concept is the same, but the formula for the calculations are different in the two versions. I wonder how QB64's formula compares against QB45's. If anyone has a version of QB45 they can run, can you kindly tell me what the output might be for the following: Code: (Select All) FOR i = 1 TO 20 RE: RND and RANDOMIZE information - tantalus - 04-28-2025 (04-28-2025, 08:29 AM)SMcNeill Wrote: I wonder how QB64's formula compares against QB45's. If anyone has a version of QB45 they can run, can you kindly tell me what the output might be for the following: ![]() |