Default implementation of Randomizer, returns quick random integers and floats (faster than
System.Random). See http://www.codeproject.com/Articles/25172/Simple-Random-Number-Generation
which is based on: http://www.bobwheeler.com/statistics/Password/MarsagliaPost.txt
View code on GitHub
Inheritance Hierarchy
DeltaEngine.Core Randomizer
DeltaEngine.Core PseudoRandom
Namespace: DeltaEngine.Core
Assembly: DeltaEngine (in DeltaEngine.dll) Version: 1.1.1.0 (1.1.1)
Syntax
The PseudoRandom type exposes the following members.
Constructors
Name | Description | |
---|---|---|
PseudoRandom | Initializes a new instance of the PseudoRandom class |
Methods
Name | Description | |
---|---|---|
Get(Int32, Int32) | (Overrides Randomizer Get(Int32, Int32).) | |
Get(Single, Single) | (Overrides Randomizer Get(Single, Single).) |
Remarks
Examples
[Test] public void UseDefaultRandomizer() { Assert.Less(Randomizer.Current.Get(1, 100), 100); }
[Test] public void GetRandomBrightColorUsingFixedRandomValues() { using (Randomizer.Use(new FixedRandom(new[] { 0.0f, 0.5f}))) { Assert.AreEqual(0, Randomizer.Current.Get(0, 10)); Assert.AreEqual(5, Randomizer.Current.Get(0, 10)); Assert.AreEqual(2, Randomizer.Current.Get(2, 4)); } }
[Test, Category("Slow")] public void RandomIntSanityTest() { var random = new PseudoRandom(); const int Max = 10; var wasChosen = new bool[Max]; const int Trials = Max * 1000; for (int i = 0; i < Trials; i++) wasChosen[random.Get(0, Max)] = true; for (int i = 0; i < Max; i++) Assert.IsTrue(wasChosen[i]); }
See Also