Posted on

Random Range Not Working in Unity

If you are ever trying to get a random number between 0 and 1 in Unity and end up only ever getting 0 then this might be your problem and solution. One thing you might not know about Random Range function in Unity is that the second parameter needs be plus one greater than the top number you wish to have for random pick when using ints.

The reason for this is that the Random Range function normally uses float and like when you case afloat into an int, whatever decimal numbers you have will be removed never rounding up.