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:
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.
Also:
NextInt()
returns a uniform random integer value between int.MinValue
and int.MaxValue
.
Also:
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:
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:
Generates a random double between 0
and 1
by filling the mantissa with 52 random bits.
Also:
Generates a random integer between 0
and the given max
(excluding max).
Also:
Generates a random integer between min
(including) and the given max
(excluding max).
Also:
Generates a random integer between 0
and the given max
(excluding max).
Also:
Generates a random integer between min
(including) and the given max
(excluding max).
Also:
Generates a random integer between min
(including), or 0
, and the given max
(excluding max).
Also:
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:
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.
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:
The Fill()
methods can be used to generate a large amount of random numbers to fill a custom array.