Задача: Простой генератор случайных чисел
Исходник: RandomGenerator.cs, язык: C# [code #62, hits: 14863]
автор: this [добавлен: 21.02.2006]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. class RandomGenerator
  6. {
  7. private Random gen;
  8. private int num = 0;
  9. private int[] cache;
  10.  
  11. public RandomGenerator(int Num)
  12. {
  13. this.gen = new Random(unchecked((int)DateTime.Now.Ticks));
  14. this.num = Num;
  15. this.cache = new int[Num];
  16. }
  17.  
  18. public int[] Get(int left, int right)
  19. {
  20. for (int i = 0; i < this.num; i++)
  21. {
  22. this.cache[i] = this.gen.Next(left, right);
  23. }
  24. return this.cache;
  25. }
  26. }
  27.  
RandomGenerator.cs :: Генератор случайных чисел.

Использует фукнционал встроенного объекта .NET - Random.
Тестировалось на: MS Visual Studio 2005, .NET Framework 2.0

+добавить реализацию