Thread: random()
View Single Post
06-06-13, 10:05 AM   #6
TSquared
Big Daddy!
Join Date: May 2008
Posts: 527
If you want to constrict your random range you can multiply the random number by the full range (ex - 0-4 is a range of 5 numbers so "myRand= floor(math.random() * 5)")

If you never want a number to go "back-to-back" you check if it's one less the range and if it's lower then the previous value just take your value, if it's higher add one.

If you want a random range that does not repeat until it goes through all the numbers you can make an array with the values in sequence and then sort them randomly. Then just pull them off in sequence.

(FYI - looping with random can take a random amount of time

Last edited by TSquared : 06-06-13 at 02:48 PM. Reason: DOH! forgot lua's random was 0,1 :P
  Reply With Quote