A C# version of the PCG random number generator. Currently implements the Minimal C Edition with the addition of a non-zero bounded range, boolean, random float, and float range.
Package Name | Package Version | Unity Version |
---|---|---|
com.potatointeractive.pcg | 1.2.0 | 2018.3 or newer |
namespace PcgRandom {
public static Extensions {
public static void Pcg.Shuffle<T>(this T[] array, Pcg randomizer);
public static void Pcg.Shuffle<T>(this IList<T> list, Pcg randomizer);
}
}
The Shuffle
extension function lets you randomize the order of the elements within an IList<T>
or Array
instance using the given Pcg
instance.
- ArgumentNullException : thrown if the given
Pcg
instance isnull
, as it is required to execute theShuffle
behaviour.
// The parameterless Pcg constructor uses a constant, default seed
// We are using it show that Shuffle produces a consistent result
Pcg randomizer = new Pcg();
List<int> list = new List<int>() {
8, 3, -2, 39, 1290, 199, -29, 55, 1, 0
};
Debug.LogFormat("`{0}'", list[0]); // prints `8'
list.Shuffle(randomizer);
Debug.LogFormat("`{0}'", list[0]); // prints `-29'
// elements shuffled to be in this order:
// -29, 3, -2, 199, 55, 8, 0, 1, 39, 1290