Skip to content

C# version of the PCG random number generator that is compatible with Unity package management

License

Notifications You must be signed in to change notification settings

tlauterbach/unity-pcg-csharp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unity-pcg-csharp

openupm

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

Extensions

Shuffle

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.

Exceptions

  • ArgumentNullException : thrown if the given Pcg instance is null, as it is required to execute the Shuffle behaviour.

Usage Example

// 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

About

C# version of the PCG random number generator that is compatible with Unity package management

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%