I’ve found Unity’s Random.Range to not be so random when using small ranges of numbers.
It seems to work in ‘groups’…
So if you’re using…
Random.Range(0, 2);
It will return ‘0’, 3 or 4 times in a row, or if the range is 0 - 3, then it may return ‘2’ several times in a row.
I’ve even had it, when testing my monster truck game, often return the same 3 race variables 2 or 3 races in a row, i.e night racing, in the snow, in a clockwise direction!!
A more ‘random’ approach in my opinion to get a bool is to have a large range of numbers, then test if the number is odd or even…
Well, that’s expected (and desired) behavior. It’s random after all. There’s no statistical difference whatsoever between “Random.Range(0, 2)” and “Random.Range(0, 100) % 2”. The second method is definitely no more “random” than the first. However Antony Blackett’s method of using Random.value is the simplest and most straightforward, so just use that.
I understand what you’re saying, but from the 18 months I’ve spent on this current project, Random.Range really has continuously repeated items many more times than it should have, and it certainly didn’t seem random. Even selecting a random song out of 10 songs using Random.Range, it happens very often that the same song gets played 3 times in a row! Then I go and have 4 or 5 of the same races in a row that have a 33% chance each time of being selected!
As soon as I expanded the range of values assigned to Random.Range, i.e making the random range 1-30, then assigning each of those into crisp sets, I found the music selection, and track/environment selection was a lot more ‘random’, and I hardly experience repeats any more.