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.
Syntax
[Serializable]
public struct Random
Constructors
Random(UInt32)
Constructs a Random instance with a given seed value. The seed must be non-zero.
Declaration
Parameters
Type |
Name |
Description |
System.UInt32 |
seed |
|
Fields
state
Declaration
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
Returns
Type |
Description |
System.Boolean |
|
NextBool2()
Returns a uniformly random bool2 value.
Declaration
Returns
NextBool3()
Returns a uniformly random bool3 value.
Declaration
Returns
NextBool4()
Returns a uniformly random bool4 value.
Declaration
Returns
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
NextDouble2(double2)
Returns a uniformly random double2 value with all components in the interval [0, max).
Declaration
public double2 NextDouble2(double2 max)
Parameters
Returns
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
Returns
NextDouble2Direction()
Returns a unit length double2 vector representing a uniformly random 2D direction.
Declaration
public double2 NextDouble2Direction()
Returns
NextDouble3()
Returns a uniformly random double3 value with all components in the interval [0, 1).
Declaration
public double3 NextDouble3()
Returns
NextDouble3(double3)
Returns a uniformly random double3 value with all components in the interval [0, max).
Declaration
public double3 NextDouble3(double3 max)
Parameters
Returns
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
Returns
NextDouble3Direction()
Returns a unit length double3 vector representing a uniformly random 3D direction.
Declaration
public double3 NextDouble3Direction()
Returns
NextDouble4()
Returns a uniformly random double4 value with all components in the interval [0, 1).
Declaration
public double4 NextDouble4()
Returns
NextDouble4(double4)
Returns a uniformly random double4 value with all components in the interval [0, max).
Declaration
public double4 NextDouble4(double4 max)
Parameters
Returns
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
Returns
NextFloat()
Returns a uniformly random float value in the interval [0, 1).
Declaration
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
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
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
Returns
NextFloat2Direction()
Returns a unit length float2 vector representing a uniformly random 2D direction.
Declaration
public float2 NextFloat2Direction()
Returns
NextFloat3()
Returns a uniformly random float3 value with all components in the interval [0, 1).
Declaration
public float3 NextFloat3()
Returns
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
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
Returns
NextFloat3Direction()
Returns a unit length float3 vector representing a uniformly random 3D direction.
Declaration
public float3 NextFloat3Direction()
Returns
NextFloat4()
Returns a uniformly random float4 value with all components in the interval [0, 1).
Declaration
public float4 NextFloat4()
Returns
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
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
Returns
NextInt()
Returns a uniformly random int value in the interval [-2147483647, 2147483647].
Declaration
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
Returns
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
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
Returns
NextInt3()
Returns a uniformly random int3 value with all components in the interval [-2147483647, 2147483647].
Declaration
Returns
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
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
Returns
NextInt4()
Returns a uniformly random int4 value with all components in the interval [-2147483647, 2147483647].
Declaration
Returns
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
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
Returns
NextQuaternionRotation()
Returns a unit length quaternion representing a uniformly 3D rotation.
Declaration
public quaternion NextQuaternionRotation()
Returns
NextUInt()
Returns a uniformly random uint value in the interval [0, 4294967294].
Declaration
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
Returns
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
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
Returns
NextUInt3()
Returns a uniformly random uint3 value with all components in the interval [0, 4294967294].
Declaration
Returns
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
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
Returns
NextUInt4()
Returns a uniformly random uint4 value with all components in the interval [0, 4294967294].
Declaration
Returns
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
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
Returns