Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


NextFloat

Returns a uniformly random float value in the interval [0, 1).
Read time 1 minuteLast updated 4 days ago

Definition

NextFloat()

Returns a uniformly random float value in the interval [0, 1).
public float NextFloat()

Returns

Type

Description

floatA uniformly random float value in the range [0, 1).

NextFloat(float)

Returns a uniformly random float value in the interval [0, max).
public float NextFloat(float max)

Parameters

The maximum value to generate, exclusive.

Returns

Type

Description

floatA uniformly random float value in the range [0, max).

NextFloat(float, float)

Returns a uniformly random float value in the interval [min, max).
public float NextFloat(float min, float max)

Parameters

The minimum value to generate, inclusive.

The maximum value to generate, exclusive.

Returns

Type

Description

floatA uniformly random float value in the range [min, max).

Remarks

The result is computed as
NextFloat() * (max - min) + min
, so floating-point rounding can in rare cases return a value equal to
max
rather than strictly less than it. Clamp the result if you require a value strictly less than
max
.