BASIC

Author Topic: random numbers  (Read 2304 times)

Offline Richard Rae

  • Mr. Drawsprite
  • **
  • Posts: 79
    • View Profile
random numbers
« 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.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5014
  • O Rly?
    • View Profile
random numbers
« Reply #1 on: 2007-Apr-24 »
it returns a Integer, and every loop are a different number
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Synthetic

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
    • ClanBam
random numbers
« Reply #2 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
"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.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
random numbers
« Reply #3 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