I want to get the value of -1 or 1 randomly.
I know we can use Random.Range(min, max) for this, but if I use -1 and 1, then 0 is of course also included, which I do not want.
What simple method is there to get this right? So far I have done two different ways to overcome this problem. I used 1 and 2 for min and max, and if it’s 1 then I set the value to -1, if it’s something else, then I set the value to +1. The other method is to put the random into a loop, and only quit the loop if the value is not 0.
But I don’t think either of these two solutions are probably a good habit to get into, especially the loop one.
Would appreciate any suggestions. Perhaps there’s an altogether different method?
how does it work? please tell me. I want to know!
– ed321ali123in case of random integer the second argument is exclusive. that mean a Random.range(0,50) is a random between 0 and 49. So Random.Range(0,2) can't give you a result of 2, but only 1 or 0. Then, it's just basic mathematics; (1 * 2) - 1 = 2 - 1 = 1 (0 * 2) - 1 = 0 -1 = -1 why is the second argument exclusiv for int and inclusiv for float ? i don't know, probably special cases of mathematics which cause errors.
– Wamoga