• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

### #ActualBacterius

Posted 21 October 2012 - 04:05 PM

is there anyway I can generate a random number only once and do not have it repeat.

If you mean produce a sequence of numbers where no number is repeated, like 3, 1, 9, 5, 2, 4, ... then sure, it's very easy:

1. generate an array [0, 1, 2, 3, 4, ... as much as you need, pretty much put the numbers you want in there]
2. for each element A in the array...
----> select a random element B in the array
----> swap elements A and B
3. iterate through the modified array to get your repeat-free random numbers

See Fisher-Yates shuffle. Is this what you meant?

### #2Bacterius

Posted 21 October 2012 - 04:04 PM

is there anyway I can generate a random number only once and do not have it repeat.

If you mean produce a sequence of numbers where no number is repeated, like 3, 1, 9, 5, 2, 4, ... then sure, it's very easy:

1. generate an array [0, 1, 2, 3, 4, ... as much as you need]
2. for each element A in the array...
----> select a random element B in the array
----> swap elements A and B
3. iterate through the modified array to get your repeat-free random numbers

See Fisher-Yates shuffle. Is this what you meant?

### #1Bacterius

Posted 21 October 2012 - 04:04 PM

is there anyway I can generate a random number only once and do not have it repeat.

If you mean produce a sequence of numbers where no number is repeated, like 3, 1, 9, 5, 2, 4, ... then sure, it's very easy:

1. generate an array [0, 1, 2, 3, 4, ... as much as you need]
2. for each element A in the array...
----> select a random element B in the array
----> swap elements A and B

See Fisher-Yates shuffle. Is this what you meant?

PARTNERS