Scripting API

Random

struct in Unity.Mathematics · Unity.Mathematics

29 of 29 of Unity's members
In Tassix

A small, fast pseudorandom generator: a 32-bit xorshift (13, 17, 5) whose state must never be zero. Each draw takes the current state and then advances it; floats come from the state's top 23 bits, ranges from the state scaled by the range's width.

Constructors 1

Random(uint seed)

Fields 1

uint state

Methods 27

static Random CreateFromIndex(uint index)

A generator for an index, seeded by its Wang hash (so neighboring indices aren't correlated).

void InitState(uint seed = 0x6E624EB7u)
bool NextBool()
bool2 NextBool2()
bool3 NextBool3()
bool4 NextBool4()
double NextDouble()
double NextDouble(double max)
double NextDouble(double min, double max)
double2 NextDouble2()
double2 NextDouble2(double2 max)
double2 NextDouble2(double2 min, double2 max)
double2 NextDouble2Direction()
double3 NextDouble3()
double3 NextDouble3(double3 max)
double3 NextDouble3(double3 min, double3 max)
double3 NextDouble3Direction()
double4 NextDouble4()
double4 NextDouble4(double4 max)
double4 NextDouble4(double4 min, double4 max)
float NextFloat()
float NextFloat(float max)
float NextFloat(float min, float max)
float2 NextFloat2()
float2 NextFloat2(float2 max)
float2 NextFloat2(float2 min, float2 max)
float2 NextFloat2Direction()
float3 NextFloat3()
float3 NextFloat3(float3 max)
float3 NextFloat3(float3 min, float3 max)
float3 NextFloat3Direction()

A uniformly distributed unit vector: z uniform in [-1, 1], then an angle around it.

float4 NextFloat4()
float4 NextFloat4(float4 max)
float4 NextFloat4(float4 min, float4 max)
int NextInt()
int NextInt(int max)
int NextInt(int min, int max)
int2 NextInt2()
int2 NextInt2(int2 max)
int2 NextInt2(int2 min, int2 max)
int3 NextInt3()
int3 NextInt3(int3 max)
int3 NextInt3(int3 min, int3 max)
int4 NextInt4()
int4 NextInt4(int4 max)
int4 NextInt4(int4 min, int4 max)
quaternion NextQuaternionRotation()

A uniformly distributed rotation (Shoemake's method), with w kept non-negative.

uint NextUInt()
uint NextUInt(uint max)
uint NextUInt(uint min, uint max)
uint2 NextUInt2()
uint2 NextUInt2(uint2 max)
uint2 NextUInt2(uint2 min, uint2 max)
uint3 NextUInt3()
uint3 NextUInt3(uint3 max)
uint3 NextUInt3(uint3 min, uint3 max)
uint4 NextUInt4()
uint4 NextUInt4(uint4 max)
uint4 NextUInt4(uint4 min, uint4 max)

Checked against Unity

Conformance scenarios that exercise it, recorded in Unity and compared event by event.