The question is answered, right answer was accepted
Randoming in a Randomed variable
Hi! Got a new problem. I got several int, which is already randomed. example:
int one = Random.Range(0, 5); int two = Random.Range(6, 10); int three = Random.Range(11, 15);
Now , what i need is the int one two three randomed once again. in my project is got more variable but i think this enough for describing what i am confused about.
Edit: Sorry for haven't make this clear. What i want to do is an example :
the variable above already done randomed, the one = 3; the two = 8; the three = 13;
now i want to randoming between the 3, 8 and 13. for an example a new variable called Final only can get 3,8 and 13. sorry for bad explanation , english not my main languange thou. thanks for any help !
Answer by dacarrera · Nov 25, 2016 at 11:15 AM
To randomize again, you'll want to create a function for randomizing your variables. Right now when your script is executed, Random.Range(0,5)
runs and assigns a value to one
. This only happens once. A workaround for this is to create a function for creating a random int and call it whenever you need your variables to be randomized.
// Randomize a declared variable
public void newRandomInt(){
one = Random.Range(0,5);
two = Random.Range(6,10);
three = Random.Range(11,15);
}
Now, whenever you want your variables to be randomized again, just call newRandomInt();
to reassign the values.
i'm sorry i think i didn't make my question pretty clear. english not my main languange thou. so what i want is like we rando$$anonymous$$g again between one two and three. for an example, one got values at 3, two got values at 7 and three got values at 13 after rando$$anonymous$$g. now i only want rando$$anonymous$$g from 3,7, or 13 to show up.