Random.Range
static float Range(float min, float max);
Description
Returns a random float number between and min [inclusive] and max [inclusive] (Read Only).
I random float max inclusive or not?
Random.Range
static float Range(float min, float max);
Description
Returns a random float number between and min [inclusive] and max [inclusive] (Read Only).
I random float max inclusive or not?
Yes, it’s inclusive, as stated in the docs. Note however that the int Random.Range is exclusive of the Max value.
In Unity 4.67f1, code documentation states it is inclusive although the online documentation states it is exclusive => test reveals it is exclusive
using UnityEngine;
using UnityEditor;
public class TestEditor : MonoBehaviour
{
// Random.Range( int, int ): code docu states it is inclusive, online docu says it is exclusive
[MenuItem("Tools/Test/Is Random.Range( int, int ) inclusive or exclusive")]
static void TestRandomRangeInt()
{
const int TRIES = 1000000;
bool isInclusive = false;
for( int i = 0; i < TRIES; i++ )
{
int r = Random.Range( 0, 2 );
if( r == 2 )
{
isInclusive = true;
break;
}
}
if( isInclusive )
{
Debug.LogWarning( "Random.Range( int, int ) is inclusive!" );
}
else
{
Debug.Log( "After " + TRIES + " tries Random.Range( int, int ) was not inclusive" );
}
}
}