docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method NextFloat

    | Improve this Doc View Source

    NextFloat()

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

    Declaration
    public float NextFloat()
    Returns
    Type Description
    float

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

    | Improve this Doc View Source

    NextFloat(float)

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

    Declaration
    public float NextFloat(float max)
    Parameters
    Type Name Description
    float max

    The maximum value to generate, exclusive.

    Returns
    Type Description
    float

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

    | Improve this Doc View Source

    NextFloat(float, float)

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

    Declaration
    public float NextFloat(float min, float max)
    Parameters
    Type Name Description
    float min

    The minimum value to generate, inclusive.

    float max

    The maximum value to generate, exclusive.

    Returns
    Type Description
    float

    A 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.

    • Improve this Doc
    • View Source
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)