- Home /
The question is answered, right answer was accepted
Random Range Seems... Unrandom
Hey all, I'm trying to select objects randomly from an array as such. The array is full of... kittens, and I then instantiate them in the scene.
GameObject theKitten = theKittens[Random.Range(0, theKittens.Length - 1)];
In an array full of 3 different objects it picks the same kitten virtually all the time. I've run it over and over again and it just isn't very random. Moreover, it NEVER spawns the final object in the array.
EDIT: Holy dolt batman. The end of the range is exclusive, not inclusive.
Answer by Wuzseen · Jun 04, 2013 at 03:34 AM
Random.Range is Inclusive for the first argument and Exclusive for the second.
I was being a bit silly.
Follow this Question
Related Questions
renderer.material doesnt work 3 Answers
Store multiple random integers in an array? 4 Answers
How to know what random number is chosen 2 Answers
Choose random Gameobject from array? 4 Answers
How do you get different random numbers for each object array? 1 Answer