random numbers

Previous topic - Next topic

Richard Rae

Does GL Basic return an integer or a float value with the random command?Also is there any way of making sure that it does not picked the same random number if you ask to generate one several times in one loop.

Schranz0r

it returns a Integer, and every loop are a different number
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Synthetic

Here is a simple random number generator that doesn't pick the same number:



WHILE TRUE

GetRandom:
a = RND(5)
IF a = b THEN GOTO GetRandom

KEYWAIT
PRINT a,0,0
b = a
SHOWSCREEN
WEND
"Impossible is a word people use to make themselves feel better when they quit."

My AMXMODX plugins for Day of Defeat 1.3 can be found here.

Kitty Hello

or:
Code (glbasic) Select
FUNCTION RND_no_dup: nEnd
STATIC last
LOCAL r
@redo:
     r = RND(nEnd)
     IF r=last THEN GOTO redo
     last=r
     RETURN r
ENDFUNCTION