Advertisement
AvengersAssemble

Random But Different Array Initializer

Sep 16th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Practice
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int size;
  14.             size = int.Parse(Console.ReadLine());
  15.             Random rnd = new Random();
  16.             int[] arr = new int[size];
  17.             for (int i = 0; i < arr.Length; i++)
  18.             {
  19.                 arr[i] = rnd.Next(0,10);
  20.                 for (int b = 0; b < i; b++)
  21.                 {
  22.                     while (arr[i] == arr[b])
  23.                     {
  24.                         arr[i] = rnd.Next(0, 10);
  25.                         b = 0;
  26.                     }
  27.                 }
  28.             }
  29.  
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement