(int sampleSize, int maxVal) => wH2006.NextInt32s(sampleSize, 0, maxVal); //array of random numbers public static void Shuffle <T>(this WH2006 rng, T[] array) // shuflling data // Fisher - Yates Algorithms { int n = array.Length; while (n > 1) { int k = rng.Next(n--); T temp = array[n]; array[n] = array[k]; array[k] = temp; } }
private static IList <double> GetTrialRandomNumbers(uint numTrials, Range range) { var rnd = new WH2006(RandomSeed.Robust()); // adds equally-separated values var trialNumbers = new List <double>(); var interval = range.Interval / numTrials; for (var i = 0; i < numTrials; i++) { trialNumbers.Add(range.Min + i * interval); } trialNumbers.Shuffle(rnd); return(trialNumbers); }
public static Scene testScene_featuressimulation(double distmean, double diststd, int features) { var r = new Scene(); var c = new PinholeCamera(CameraIntrinsics.GOPROHERO3_BROWNR3_AFGEROND_EXTRADIST); r.Add(c); Random rand = new WH2006(); for (int i = 0; i < features; i++) { var sensorx = rand.NextDouble() * c.Intrinsics.PictureSize.Width; var sensory = rand.NextDouble() * c.Intrinsics.PictureSize.Height; var dist = Util.NextGaussian(distmean, diststd); r.Add(CreateFeatureFromCamera(c, sensorx, sensory, dist, i)); } return(r); }
/// <summary> /// Run example /// </summary> /// <seealso cref="http://en.wikipedia.org/wiki/Random_number_generation">Random number generation</seealso> /// <seealso cref="http://en.wikipedia.org/wiki/Linear_congruential_generator">Linear congruential generator</seealso> /// <seealso cref="http://en.wikipedia.org/wiki/Mersenne_twister">Mersenne twister</seealso> /// <seealso cref="http://en.wikipedia.org/wiki/Lagged_Fibonacci_generator">Lagged Fibonacci generator</seealso> /// <seealso cref="http://en.wikipedia.org/wiki/Xorshift">Xorshift</seealso> public void Run() { // All RNG classes in MathNet have next counstructors: // - RNG(int seed, bool threadSafe): initializes a new instance with specific seed value and thread safe property // - RNG(int seed): iуууnitializes a new instance with specific seed value. Thread safe property is set to Control.ThreadSafeRandomNumberGenerators // - RNG(bool threadSafe) : initializes a new instance with the seed value set to DateTime.Now.Ticks and specific thread safe property // - RNG(bool threadSafe) : initializes a new instance with the seed value set to DateTime.Now.Ticks and thread safe property set to Control.ThreadSafeRandomNumberGenerators // All RNG classes in MathNet have next methods to produce random values: // - double[] NextDouble(int n): returns an "n"-size array of uniformly distributed random doubles in the interval [0.0,1.0]; // - int Next(): returns a nonnegative random number; // - int Next(int maxValue): returns a random number less then a specified maximum; // - int Next(int minValue, int maxValue): returns a random number within a specified range; // - void NextBytes(byte[] buffer): fills the elements of a specified array of bytes with random numbers; // All RNG classes in MathNet have next extension methods to produce random values: // - long NextInt64(): returns a nonnegative random number less than "Int64.MaxValue"; // - int NextFullRangeInt32(): returns a random number of the full Int32 range; // - long NextFullRangeInt64(): returns a random number of the full Int64 range; // - decimal NextDecimal(): returns a nonnegative decimal floating point random number less than 1.0; // 1. Multiplicative congruential generator using a modulus of 2^31-1 and a multiplier of 1132489760 var mcg31M1 = new Mcg31m1(1); Console.WriteLine(@"1. Generate 10 random double values using Multiplicative congruential generator with a modulus of 2^31-1 and a multiplier of 1132489760"); var randomValues = mcg31M1.NextDouble(10); for (var i = 0; i < randomValues.Length; i++) { Console.Write(randomValues[i].ToString("N") + @" "); } Console.WriteLine(); Console.WriteLine(); // 2. Multiplicative congruential generator using a modulus of 2^59 and a multiplier of 13^13 var mcg59 = new Mcg59(1); Console.WriteLine(@"2. Generate 10 random integer values using Multiplicative congruential generator with a modulus of 2^59 and a multiplier of 13^13"); for (var i = 0; i < 10; i++) { Console.Write(mcg59.Next() + @" "); } Console.WriteLine(); Console.WriteLine(); // 3. Random number generator using Mersenne Twister 19937 algorithm var mersenneTwister = new MersenneTwister(1); Console.WriteLine(@"3. Generate 10 random integer values less then 100 using Mersenne Twister 19937 algorithm"); for (var i = 0; i < 10; i++) { Console.Write(mersenneTwister.Next(100) + @" "); } Console.WriteLine(); Console.WriteLine(); // 4. Multiple recursive generator with 2 components of order 3 var mrg32K3A = new Mrg32k3a(1); Console.WriteLine(@"4. Generate 10 random integer values in range [50;100] using multiple recursive generator with 2 components of order 3"); for (var i = 0; i < 10; i++) { Console.Write(mrg32K3A.Next(50, 100) + @" "); } Console.WriteLine(); Console.WriteLine(); // 5. Parallel Additive Lagged Fibonacci pseudo-random number generator var palf = new Palf(1); Console.WriteLine(@"5. Generate 10 random bytes using Parallel Additive Lagged Fibonacci pseudo-random number generator"); var bytes = new byte[10]; palf.NextBytes(bytes); for (var i = 0; i < bytes.Length; i++) { Console.Write(bytes[i] + @" "); } Console.WriteLine(); Console.WriteLine(); // 6. A random number generator based on the "System.Security.Cryptography.RandomNumberGenerator" class in the .NET library var systemCryptoRandomNumberGenerator = new SystemCryptoRandomNumberGenerator(); Console.WriteLine(@"6. Generate 10 random decimal values using RNG based on the 'System.Security.Cryptography.RandomNumberGenerator'"); for (var i = 0; i < 10; i++) { Console.Write(systemCryptoRandomNumberGenerator.NextDecimal().ToString("N") + @" "); } Console.WriteLine(); Console.WriteLine(); // 7. Wichmann-Hill’s 1982 combined multiplicative congruential generator var rngWh1982 = new WH1982(); Console.WriteLine(@"7. Generate 10 random full Int32 range values using Wichmann-Hill’s 1982 combined multiplicative congruential generator"); for (var i = 0; i < 10; i++) { Console.Write(rngWh1982.NextFullRangeInt32() + @" "); } Console.WriteLine(); Console.WriteLine(); // 8. Wichmann-Hill’s 2006 combined multiplicative congruential generator. var rngWh2006 = new WH2006(); Console.WriteLine(@"8. Generate 10 random full Int64 range values using Wichmann-Hill’s 2006 combined multiplicative congruential generator"); for (var i = 0; i < 10; i++) { Console.Write(rngWh2006.NextFullRangeInt32() + @" "); } Console.WriteLine(); Console.WriteLine(); // 9. Multiply-with-carry Xorshift pseudo random number generator var xorshift = new Xorshift(); Console.WriteLine(@"9. Generate 10 random nonnegative values less than Int64.MaxValue using Multiply-with-carry Xorshift pseudo random number generator"); for (var i = 0; i < 10; i++) { Console.Write(xorshift.NextInt64() + @" "); } Console.WriteLine(); }
public void StaticSamplesConsistent() { Assert.That(WH2006.Doubles(1000, 1), Is.EqualTo(new WH2006(1).NextDoubles(1000)).Within(1e-12).AsCollection); }
public void Generate() { DataBaseFactory.UserNameOverride = Data.DatabaseName; if (File.Exists(DataBaseFactory.DatabasePath)) { File.Delete(DataBaseFactory.DatabasePath); } PaperFormat[] formats = { new PaperFormat(50, 100), new PaperFormat(50, 70), new PaperFormat(30, 45), new PaperFormat(20, 30), }; RandomSource random = new WH2006(false); DoubleRundom iterations = new DoubleRundom(random, 1, 10); DoubleRundom speed = new DoubleRundom(random, 0, 10); SpeedNotes speedNotes = new SpeedNotes("Speed.Notes"); _iterationTime = new DoubleRundom(random, 5, 20); _setupTime = new DoubleRundom(random, 10, 120); double[] quarterMultipler = { 1.0, 0.5, 1.5, 2.0 }; int compledAmount = Data.ToGenerate * 4; int currentAmount = 0; int error = 0; DateTime datetime = DateTime.Now; for (int i = 0; i < compledAmount; i++) { if (datetime.Hour > 16) { int toZero = 24 - datetime.Hour; datetime += TimeSpan.FromHours(toZero + 7); } int currentQuater; if (datetime.Month <= 3) { currentQuater = 0; } else if (datetime.Month <= 6) { currentQuater = 1; } else if (datetime.Month <= 9) { currentQuater = 2; } else { currentQuater = 3; } var realIterations = iterations.Next(); var realamount = random.Next(100, 10000); var realSpeed = speedNotes.CalculateSpeed(speed.Next() >= 5 ? 15 : 4); var realformat = formats[random.Next(0, 3)]; var realtime = CalculateTime(realamount, realSpeed, realIterations, quarterMultipler[currentQuater], realformat, out var realProblem, out var realBigProblem, out var iterationMinutes, out var setupMinutes); SaveInput input = new SaveInput(realamount, realIterations, realProblem, realBigProblem, realformat, realSpeed, datetime, realtime, iterationMinutes, setupMinutes); datetime += realtime; var result = BusinessRules.Save.Action(input); if (!result.Succsess) { error++; } ProgressAction(new Progress { Amount = compledAmount, Generated = currentAmount, Errors = error }); currentAmount++; } }