Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a random number wihout RND.
#1
A while back I found some TI-84 code for a random number generator.  Played with it for a while, adapting it to QB64.  Messed with the calcs.  Gave it more randomness (I think) by feeding it the starting x/y position of the QB84 windows that seems to be placed randomly, and threw in TIMER for good luck.  I don't really understand it, but here it is for anyone interested in such a function.

- Dav

Code: (Select All)
'========
'RAND.BAS
'========
'Get a random number, without using RND
'Adapted for QB64 from TI-84 source found online.
'Thrown together By Dav, SEP/2023

'Since the QB64 window x/y position always starts at a
'random position, I'm using that as the seed starter.

_Delay .25

DIM SHARED seed: seed = _SCREENX * _SCREENY * TIMER

SCREEN _NEWIMAGE(800, 600, 32)

'Blocks of random size of random colors at random positions.

DO
    x = Rand(_WIDTH)
    y = Rand(_HEIGHT)
    s = Rand(100)
    r = Rand(255): g = Rand(255): b = Rand(255)
    LINE (x, y)-STEP(s, s), _RGB(r, g, b), BF
    _LIMIT 1000
LOOP


FUNCTION Rand (num)
    DIM z AS _INTEGER64, k AS _INTEGER64
    seed2 = seed * TIMER
    k = seed / 53668
    seed = 40014 * (seed - k * 53668) - k * 12211
    IF seed < 0 THEN seed = seed + 2147483563
    k = seed2 / 52774
    seed2 = 40692 * (seed2 - k * 52774) - k * 3791
    IF seed2 < 0 THEN seed2 = seed2 + 2147483563
    z = seed - seed2
    IF z < 1 THEN z = z + 2147483563
    Rand = z * 4.656613E-10 * 190000000 MOD num
END FUNCTION

Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
Getting a random number wihout RND. - by Dav - 09-30-2023, 11:01 PM
RE: Getting a random number wihout RND. - by Dav - 09-30-2023, 11:06 PM
RE: Getting a random number wihout RND. - by Dav - 09-30-2023, 11:27 PM
RE: Getting a random number wihout RND. - by Dav - 10-01-2023, 01:45 AM
RE: Getting a random number wihout RND. - by Pete - 07-17-2024, 07:00 PM
RE: Getting a random number wihout RND. - by Pete - 07-17-2024, 07:42 PM
RE: Getting a random number wihout RND. - by Pete - 07-17-2024, 09:00 PM
RE: Getting a random number wihout RND. - by Pete - 07-17-2024, 10:08 PM



Users browsing this thread: 2 Guest(s)