Last active
August 29, 2015 13:56
-
-
Save jgold6/9078786 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int[] Num2 = new int[141]; //array for random numbers | |
| // Fill the array with numbers from 0 to 140 | |
| for (int i = 0; i < Num2.Length; i++) { | |
| Num2[i] = i; | |
| } | |
| // Shuffle Array | |
| Random rnd = new Random((int)DateTime.Now.Ticks); // seed the random number generator based on the time so you don't get the same sequence repeatedly | |
| for (int i = Num2.Length; i > 1; i--) { | |
| // Pick random element to swap | |
| int j = rnd.Next(1, 141); | |
| // Swap | |
| int temp = Num2[j]; | |
| Num2[j] = Num2[i - 1]; | |
| Num2[i-1] = temp; | |
| } | |
| // Output shuffled array to console - this block can be removed | |
| for (int i = 1; i < Num2.Length; i++) { | |
| Console.WriteLine("Element {0} = {1}", i, Num2[i]); | |
| } | |
| // Check for doubles (there can't be, but always good to double check - this block can be removed | |
| for (int i = 1; i < Num2.Length - 1; i++) { | |
| for (int j = i+1; j < Num2.Length; j++) { | |
| if (Num2[i] == Num2[j]) | |
| Console.WriteLine("---------------------Duplicate found {0} = {1}", Num2[i], Num2[j]); | |
| else | |
| Console.WriteLine("No Duplicate {0} != {1}", Num2[i], Num2[j]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment