Burst is very restrictive in terms of inheritance and extensions so every Random Number Generator implements all the methods below. These methods are generated and identical between the RNG implementation.
Because of this highly duplicate nature, they are presented in this form and not in a classical Doxygen or similar.
Basic constructor that initializes the RNG with the given seed. Internally the SplitMix
function is used, to initialize
the internal state in an efficient way
Specialized method for IParallelFor
Jobs or normal for
loops. Use the index of the loop or from the job as first
parameter and a custom offset to make it unique.
Specialized method to initialize the RNG inside the ECS system. The chunkIndexInQuery
and entityIndexInChuck
can
be acquired very performantly with [ChunkIndexInQuery]
and [EntityIndexInChunk]
. Custom parameters globalTime
and customSeed
can be set, so the seed doesn’t statically depend on the index inside the ECS system.
CreateFrom
Time allows to use Unity’s time to provide a seed. A custom offset customSeed
can be supplied, which is
combined with the time to provide a unique seed.
The CreateAdvanced(...)
method allows to directly initialize the internal RNG state without the custom hash function
or any other general initialization code. This is an advanced method.
Also:
bool2 NextBool2()
bool3 NextBool3()
bool4 NextBool4()
NextBool()
returns a random boolean value with a 50% chance of being true
and a 50% chance of being false
.
This method is good for generating single booleans, but if a lot of booleans are needed it might be better to
use NextUInt()
or NextULong()
(depending on the size of the RNG) and then use bit operations to extract the
booleans.
Definitions:
Color NextColorHSV(float hueMin, float hueMax, float saturationMin, float saturationMax, float valueMin, float valueMax, float alphaMin, float alphaMax)
Color NextColorRGB(float rMin, float rMax, float gMin, float gMax, float bMin, float bMax, float alphaMin, float alphaMax);
NextColorHSV()
generates a random color in the specified range and returns the Unity Color
struct for it.
NextColorRGB()
does the same, but the ranges can be specified in the RGB color range. Note that Color
structure can
only save color in the RGB colorspace, so the HSV version does a conversion step after the generation.
Also:
int2 NextInt2()
int3 NextInt3()
int4 NextInt4()
NextInt()
returns a uniform random integer value between int.MinValue
and int.MaxValue
.
Also:
uint2 NextUInt2()
uint3 NextUInt3()
uint4 NextUInt4()
NextUInt()
returns a uniform random unsigned integer value between uint.MinValue
and uint.MaxValue
.
NextULong()
returns a uniform random unsigned long integer value between 0
and ulong.MaxValue
.
Also:
float2 NextFloat2()
float3 NextFloat3()
float4 NextFloat4()
Generates a random float between 0
and 1
by filling the mantissa with 23 random bits. Alternative Generation methods
can be found in Conversion.AsFloatXXX
Variants.
Also:
double2 NextDouble2()
double3 NextDouble3()
double4 NextDouble4()
Generates a random double between 0
and 1
by filling the mantissa with 52 random bits.
Also:
int NextInt(int max)
int2 NextInt2(int max)
int3 NextInt3(int max)
int4 NextInt4(int max)
int2 NextInt2(int2 max)
int3 NextInt3(int3 max)
int4 NextInt4(int4 max)
Generates a random integer between 0
and the given max
(excluding max).
Also:
int NextInt(int min, int max)
int2 NextInt2(int min, int max)
int3 NextInt3(int min, int max)
int4 NextInt4(int min, int max)
int2 NextInt2(int2 min, int2 max)
int3 NextInt3(int3 min, int3 max)
int4 NextInt4(int4 min, int4 max)
Generates a random integer between min
(including) and the given max
(excluding max).
Also:
uint2 NextUInt2(uint max)
uint3 NextUInt3(uint max)
uint4 NextUInt4(uint max)
uint2 NextUInt2(uint2 max)
uint3 NextUInt3(uint3 max)
uint4 NextUInt4(uint4 max)
Generates a random integer between 0
and the given max
(excluding max).
Also:
uint2 NextUInt2(uint min, uint max)
uint3 NextUInt3(uint min, uint max)
uint4 NextUInt4(uint min, uint max)
uint2 NextUInt2(uint2 min, uint2 max)
uint3 NextUInt3(uint3 min, uint3 max)
uint4 NextUInt4(uint4 min, uint4 max)
Generates a random integer between min
(including) and the given max
(excluding max).
Also:
ulong NextULong(ulong max)
ulong NextULong(ulong min, ulong max)
Generates a random integer between min
(including), or 0
, and the given max
(excluding max).
Also:
float2 NextFloat2(float max)
float3 NextFloat3(float max)
float4 NextFloat4(float max)
float2 NextFloat2(float2 max)
float3 NextFloat3(float3 max)
float4 NextFloat4(float4 max)
Generates a random float between 0
(including) and the given max
(excluding max). Note that the internal
multiplication, that has to be done to produce a number in that range, can sometimes include the maximum due to
floating point inaccuracies.
Also:
float2 NextFloat2(float min, float max)
float3 NextFloat3(float min, float max)
float4 NextFloat4(float min, float max)
float2 NextFloat2(float2 min, float2 max)
float3 NextFloat3(float3 min, float3 max)
float4 NextFloat4(float4 min, float4 max)
Generates a random float between min
(including) and the given max
(excluding max). Note that the internal
multiplication, that has to be done to produce a number in that range, can sometimes include the maximum due to
floating point inaccuracies.
A unit length quaternion representing a uniformly 3D rotation.
Also:
float3 NextFloat3Direction()
float3 NextFloat3FastDirection()
double3 NextDouble3Direction()
New in 1.1.0Unit length random vector with the given dimensions. Can also be considered as a point on a unit circle.
Randomly generates a point uniformly inside the unit circle NextInsideCircle()
or a point inside
the unit sphere NextInsideSphere()
. The unit circle/sphere has a maximum radius of one and the generated
values are not on the hull of the sphere/circle (the length of the vector is always smaller than one).
If numbers on the hull of the circle/sphere are needed, the NextFloat2Direction()
variants can be used.
The Shuffle(ref X)
methods do uniformly and randomly shuffle any given NativeArray
, NativeSlice
or Span
. The
array contents has to be a struct
(burst limitation).
Also:
Fill(ref Span<X> t)
Fill(ref NativeSlice<X> t)
Fill(ref NativeArray<X> t)
The Fill()
methods can be used to generate a large amount of random numbers to fill a custom array.