Disreguard random number after use...

Using Random.Range, i choose a number at random from 1-10.

But i only want each number to be used once, so if i roll a 3, then re-roll 3 i want it to either roll again, or take 3 out of the list of randomly chooseable (did i just make up a word?) numbers.

Are either of these things possible?

Thanks, Tom :slight_smile:

Sure. You’ll just need to make a random number “pool” of sorts. This can just be a List or something similar. Fill it with the numbers you want, then do a Random.Range from 0 to the length of the list. Get the value, remove that index from the list, and repeat until the list is empty.

sure just store ur last number in a variable

lets say ur first roll is 3 then u store it in a variable

and compare.

if (the new number == to the last number){
re-roll again.

the only on or two ways i can think of that are different than those already posted at the moment would be to either the best seems to be:

have an array of already rolled numbers that gets added to every roll and then if a rolled number is equal to any number in that array the code would roll again until it got a number not included in the array. when the array got filled it would be reset.

so for example (sorry this is off the top of my head):

var rolledNumbers : int[]
var rolledNumber : int;
function Start(){
    rolledNumbers = new int[10];
function onRoll(){
    var tempNum : int = Random.Range(1,10);
    if( rolledNumbers[tempNum]=tempNum){
            rolledNumber = tempNum;
            rolledNumbers[tempNum] = tempNum;