Struct Random | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    Struct Random

    Random Number Generator based on xorshift. Designed for minimal state (32bits) to be easily embeddable into components. Core functionality is integer multiplication free to improve vectorization on less capable SIMD instruction sets.

    Inherited Members
    System.ValueType.Equals(System.Object)
    System.ValueType.GetHashCode()
    System.ValueType.ToString()
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetType()
    Namespace: Unity.Mathematics
    Syntax
    [Serializable]
    public struct Random

    Constructors

    Random(UInt32)

    Constructs a Random instance with a given seed value. The seed must be non-zero.

    Declaration
    public Random(uint seed)
    Parameters
    Type Name Description
    System.UInt32 seed

    Fields

    state

    Declaration
    public uint state
    Field Value
    Type Description
    System.UInt32

    Methods

    InitState(UInt32)

    Initialized the state of the Random instance with a given seed value. The seed must be non-zero.

    Declaration
    public void InitState(uint seed = 1851936439U)
    Parameters
    Type Name Description
    System.UInt32 seed

    NextBool()

    Returns a uniformly random bool value.

    Declaration
    public bool NextBool()
    Returns
    Type Description
    System.Boolean

    NextBool2()

    Returns a uniformly random bool2 value.

    Declaration
    public bool2 NextBool2()
    Returns
    Type Description
    bool2

    NextBool3()

    Returns a uniformly random bool3 value.

    Declaration
    public bool3 NextBool3()
    Returns
    Type Description
    bool3

    NextBool4()

    Returns a uniformly random bool4 value.

    Declaration
    public bool4 NextBool4()
    Returns
    Type Description
    bool4

    NextDouble()

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

    Declaration
    public double NextDouble()
    Returns
    Type Description
    System.Double

    NextDouble(Double)

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

    Declaration
    public double NextDouble(double max)
    Parameters
    Type Name Description
    System.Double max
    Returns
    Type Description
    System.Double

    NextDouble(Double, Double)

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

    Declaration
    public double NextDouble(double min, double max)
    Parameters
    Type Name Description
    System.Double min
    System.Double max
    Returns
    Type Description
    System.Double

    NextDouble2()

    Returns a uniformly random double2 value with all components in the interval [0, 1).

    Declaration
    public double2 NextDouble2()
    Returns
    Type Description
    double2

    NextDouble2(double2)

    Returns a uniformly random double2 value with all components in the interval [0, max).

    Declaration
    public double2 NextDouble2(double2 max)
    Parameters
    Type Name Description
    double2 max
    Returns
    Type Description
    double2

    NextDouble2(double2, double2)

    Returns a uniformly random double2 value with all components in the interval [min, max).

    Declaration
    public double2 NextDouble2(double2 min, double2 max)
    Parameters
    Type Name Description
    double2 min
    double2 max
    Returns
    Type Description
    double2

    NextDouble2Direction()

    Returns a unit length double2 vector representing a uniformly random 2D direction.

    Declaration
    public double2 NextDouble2Direction()
    Returns
    Type Description
    double2

    NextDouble3()

    Returns a uniformly random double3 value with all components in the interval [0, 1).

    Declaration
    public double3 NextDouble3()
    Returns
    Type Description
    double3

    NextDouble3(double3)

    Returns a uniformly random double3 value with all components in the interval [0, max).

    Declaration
    public double3 NextDouble3(double3 max)
    Parameters
    Type Name Description
    double3 max
    Returns
    Type Description
    double3

    NextDouble3(double3, double3)

    Returns a uniformly random double3 value with all components in the interval [min, max).

    Declaration
    public double3 NextDouble3(double3 min, double3 max)
    Parameters
    Type Name Description
    double3 min
    double3 max
    Returns
    Type Description
    double3

    NextDouble3Direction()

    Returns a unit length double3 vector representing a uniformly random 3D direction.

    Declaration
    public double3 NextDouble3Direction()
    Returns
    Type Description
    double3

    NextDouble4()

    Returns a uniformly random double4 value with all components in the interval [0, 1).

    Declaration
    public double4 NextDouble4()
    Returns
    Type Description
    double4

    NextDouble4(double4)

    Returns a uniformly random double4 value with all components in the interval [0, max).

    Declaration
    public double4 NextDouble4(double4 max)
    Parameters
    Type Name Description
    double4 max
    Returns
    Type Description
    double4

    NextDouble4(double4, double4)

    Returns a uniformly random double4 value with all components in the interval [min, max).

    Declaration
    public double4 NextDouble4(double4 min, double4 max)
    Parameters
    Type Name Description
    double4 min
    double4 max
    Returns
    Type Description
    double4

    NextFloat()

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

    Declaration
    public float NextFloat()
    Returns
    Type Description
    System.Single

    NextFloat(Single)

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

    Declaration
    public float NextFloat(float max)
    Parameters
    Type Name Description
    System.Single max
    Returns
    Type Description
    System.Single

    NextFloat(Single, Single)

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

    Declaration
    public float NextFloat(float min, float max)
    Parameters
    Type Name Description
    System.Single min
    System.Single max
    Returns
    Type Description
    System.Single

    NextFloat2()

    Returns a uniformly random float2 value with all components in the interval [0, 1).

    Declaration
    public float2 NextFloat2()
    Returns
    Type Description
    float2

    NextFloat2(float2)

    Returns a uniformly random float2 value with all components in the interval [0, max).

    Declaration
    public float2 NextFloat2(float2 max)
    Parameters
    Type Name Description
    float2 max
    Returns
    Type Description
    float2

    NextFloat2(float2, float2)

    Returns a uniformly random float2 value with all components in the interval [min, max).

    Declaration
    public float2 NextFloat2(float2 min, float2 max)
    Parameters
    Type Name Description
    float2 min
    float2 max
    Returns
    Type Description
    float2

    NextFloat2Direction()

    Returns a unit length float2 vector representing a uniformly random 2D direction.

    Declaration
    public float2 NextFloat2Direction()
    Returns
    Type Description
    float2

    NextFloat3()

    Returns a uniformly random float3 value with all components in the interval [0, 1).

    Declaration
    public float3 NextFloat3()
    Returns
    Type Description
    float3

    NextFloat3(float3)

    Returns a uniformly random float3 value with all components in the interval [0, max).

    Declaration
    public float3 NextFloat3(float3 max)
    Parameters
    Type Name Description
    float3 max
    Returns
    Type Description
    float3

    NextFloat3(float3, float3)

    Returns a uniformly random float3 value with all components in the interval [min, max).

    Declaration
    public float3 NextFloat3(float3 min, float3 max)
    Parameters
    Type Name Description
    float3 min
    float3 max
    Returns
    Type Description
    float3

    NextFloat3Direction()

    Returns a unit length float3 vector representing a uniformly random 3D direction.

    Declaration
    public float3 NextFloat3Direction()
    Returns
    Type Description
    float3

    NextFloat4()

    Returns a uniformly random float4 value with all components in the interval [0, 1).

    Declaration
    public float4 NextFloat4()
    Returns
    Type Description
    float4

    NextFloat4(float4)

    Returns a uniformly random float4 value with all components in the interval [0, max).

    Declaration
    public float4 NextFloat4(float4 max)
    Parameters
    Type Name Description
    float4 max
    Returns
    Type Description
    float4

    NextFloat4(float4, float4)

    Returns a uniformly random float4 value with all components in the interval [min, max).

    Declaration
    public float4 NextFloat4(float4 min, float4 max)
    Parameters
    Type Name Description
    float4 min
    float4 max
    Returns
    Type Description
    float4

    NextInt()

    Returns a uniformly random int value in the interval [-2147483647, 2147483647].

    Declaration
    public int NextInt()
    Returns
    Type Description
    System.Int32

    NextInt(Int32)

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

    Declaration
    public int NextInt(int max)
    Parameters
    Type Name Description
    System.Int32 max
    Returns
    Type Description
    System.Int32

    NextInt(Int32, Int32)

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

    Declaration
    public int NextInt(int min, int max)
    Parameters
    Type Name Description
    System.Int32 min
    System.Int32 max
    Returns
    Type Description
    System.Int32

    NextInt2()

    Returns a uniformly random int2 value with all components in the interval [-2147483647, 2147483647].

    Declaration
    public int2 NextInt2()
    Returns
    Type Description
    int2

    NextInt2(int2)

    Returns a uniformly random int2 value with all components in the interval [0, max).

    Declaration
    public int2 NextInt2(int2 max)
    Parameters
    Type Name Description
    int2 max
    Returns
    Type Description
    int2

    NextInt2(int2, int2)

    Returns a uniformly random int2 value with all components in the interval [min, max).

    Declaration
    public int2 NextInt2(int2 min, int2 max)
    Parameters
    Type Name Description
    int2 min
    int2 max
    Returns
    Type Description
    int2

    NextInt3()

    Returns a uniformly random int3 value with all components in the interval [-2147483647, 2147483647].

    Declaration
    public int3 NextInt3()
    Returns
    Type Description
    int3

    NextInt3(int3)

    Returns a uniformly random int3 value with all components in the interval [0, max).

    Declaration
    public int3 NextInt3(int3 max)
    Parameters
    Type Name Description
    int3 max
    Returns
    Type Description
    int3

    NextInt3(int3, int3)

    Returns a uniformly random int3 value with all components in the interval [min, max).

    Declaration
    public int3 NextInt3(int3 min, int3 max)
    Parameters
    Type Name Description
    int3 min
    int3 max
    Returns
    Type Description
    int3

    NextInt4()

    Returns a uniformly random int4 value with all components in the interval [-2147483647, 2147483647].

    Declaration
    public int4 NextInt4()
    Returns
    Type Description
    int4

    NextInt4(int4)

    Returns a uniformly random int4 value with all components in the interval [0, max).

    Declaration
    public int4 NextInt4(int4 max)
    Parameters
    Type Name Description
    int4 max
    Returns
    Type Description
    int4

    NextInt4(int4, int4)

    Returns a uniformly random int4 value with all components in the interval [min, max).

    Declaration
    public int4 NextInt4(int4 min, int4 max)
    Parameters
    Type Name Description
    int4 min
    int4 max
    Returns
    Type Description
    int4

    NextQuaternionRotation()

    Returns a unit length quaternion representing a uniformly 3D rotation.

    Declaration
    public quaternion NextQuaternionRotation()
    Returns
    Type Description
    quaternion

    NextUInt()

    Returns a uniformly random uint value in the interval [0, 4294967294].

    Declaration
    public uint NextUInt()
    Returns
    Type Description
    System.UInt32

    NextUInt(UInt32)

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

    Declaration
    public uint NextUInt(uint max)
    Parameters
    Type Name Description
    System.UInt32 max
    Returns
    Type Description
    System.UInt32

    NextUInt(UInt32, UInt32)

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

    Declaration
    public uint NextUInt(uint min, uint max)
    Parameters
    Type Name Description
    System.UInt32 min
    System.UInt32 max
    Returns
    Type Description
    System.UInt32

    NextUInt2()

    Returns a uniformly random uint2 value with all components in the interval [0, 4294967294].

    Declaration
    public uint2 NextUInt2()
    Returns
    Type Description
    uint2

    NextUInt2(uint2)

    Returns a uniformly random uint2 value with all components in the interval [0, max).

    Declaration
    public uint2 NextUInt2(uint2 max)
    Parameters
    Type Name Description
    uint2 max
    Returns
    Type Description
    uint2

    NextUInt2(uint2, uint2)

    Returns a uniformly random uint2 value with all components in the interval [min, max).

    Declaration
    public uint2 NextUInt2(uint2 min, uint2 max)
    Parameters
    Type Name Description
    uint2 min
    uint2 max
    Returns
    Type Description
    uint2

    NextUInt3()

    Returns a uniformly random uint3 value with all components in the interval [0, 4294967294].

    Declaration
    public uint3 NextUInt3()
    Returns
    Type Description
    uint3

    NextUInt3(uint3)

    Returns a uniformly random uint3 value with all components in the interval [0, max).

    Declaration
    public uint3 NextUInt3(uint3 max)
    Parameters
    Type Name Description
    uint3 max
    Returns
    Type Description
    uint3

    NextUInt3(uint3, uint3)

    Returns a uniformly random uint3 value with all components in the interval [min, max).

    Declaration
    public uint3 NextUInt3(uint3 min, uint3 max)
    Parameters
    Type Name Description
    uint3 min
    uint3 max
    Returns
    Type Description
    uint3

    NextUInt4()

    Returns a uniformly random uint4 value with all components in the interval [0, 4294967294].

    Declaration
    public uint4 NextUInt4()
    Returns
    Type Description
    uint4

    NextUInt4(uint4)

    Returns a uniformly random uint4 value with all components in the interval [0, max).

    Declaration
    public uint4 NextUInt4(uint4 max)
    Parameters
    Type Name Description
    uint4 max
    Returns
    Type Description
    uint4

    NextUInt4(uint4, uint4)

    Returns a uniformly random uint4 value with all components in the interval [min, max).

    Declaration
    public uint4 NextUInt4(uint4 min, uint4 max)
    Parameters
    Type Name Description
    uint4 min
    uint4 max
    Returns
    Type Description
    uint4
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023