Splux

Random without duplicates

Feb 20th, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1. class CRandom
  2. {
  3.     public CRandom()
  4.     {
  5.         rand = new System.Random();
  6.     }
  7.  
  8.     public void RandomSequence(int[] arr)
  9.     {
  10.         for (int i = 0; i < arr.Length; i++)
  11.         {
  12.             arr[i] = rand.Next(1, 50);
  13.             for (int j = 0; j < i; j++)
  14.             {
  15.                 while (arr[i] == arr[j])
  16.                 {
  17.                     arr[i] = rand.Next(1, 50);
  18.                 }
  19.             }
  20.         }
  21.     }
  22.  
  23.     private System.Random rand;
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment