public void MSM_Next_Test() { MSM target = new MSM(); uint max = 10; target.Srand(2); uint result = target.Next(max); Assert.IsTrue(result >= 0, "Wartosc losowa MSM jest mniejsza od 0!"); Assert.IsTrue(result <= max, "Wartosc losowa MSM jest większa niż podana wartość maksymalna!"); }
static void Main(string[] args) { AbstractRandom rand = new MSM(); rand.Srand(156654); for (int i = 0; i < 25; i++) { Console.WriteLine("Nastepna wartosc ciagu: " + rand.Next(5));; } rand.PrintValues(); Console.ReadKey(); }
public void RandomToFile(int seed, int range, int numberOfPRNGs) { String file = ""; StringBuilder stringBuilder = new StringBuilder(); String content = ""; AbstractRandom randomAbstract = new LCG(); Random random = new Random(seed); TimerManager.ClearMessage(); for (int i = 0; i < 3; i++) { stringBuilder.Clear(); if (i == 0) { randomAbstract = new LCG(); randomAbstract.Srand((uint)seed); file = "Pseudo Random Numbers LCG.csv"; } else if (i == 1) { randomAbstract = new LFG(); randomAbstract.Srand((uint)seed); file = "Pseudo Random Numbers LFG.csv"; } else if (i == 2) { randomAbstract = new MSM(); randomAbstract.Srand((uint)seed); file = "Pseudo Random Numbers MSM.csv"; } TimerManager.TimerStart(file); for (int j = 0; j < numberOfPRNGs; j++) { stringBuilder.Append(randomAbstract.Next((uint)range)); stringBuilder.Append(Environment.NewLine); } TimerManager.TimrStop(); content = stringBuilder.ToString(); WriteToFile(file, content); } file = "Pseudo Random Numbers Random C#.csv"; stringBuilder.Clear(); TimerManager.TimerStart(file); for (int j = 0; j < numberOfPRNGs; j++) { stringBuilder.Append(random.Next(range)); stringBuilder.Append(Environment.NewLine); } TimerManager.TimrStop(); MessageBox.Show("Pliki zostały wygenerowane.", "Generowanie plików"); content = stringBuilder.ToString(); WriteToFile(file, content); }