GLBasic forum

Main forum => GLBasic - en => Topic started by: Richard Rae on 2007-Apr-24

Title: random numbers
Post by: Richard Rae on 2007-Apr-24
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.
Title: random numbers
Post by: Schranz0r on 2007-Apr-24
it returns a Integer, and every loop are a different number
Title: random numbers
Post by: Synthetic on 2007-Apr-25
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
Title: random numbers
Post by: Kitty Hello on 2007-Apr-25
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