Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class RandomizeUniqueNumbersFrom1toN_Var2
- {
- static void Main ()
- {
- Console.Write("Enter a whole positive number, bigger from 1, for N = ");
- string numberStr = Console.ReadLine();
- uint numN = uint.Parse(numberStr);
- if (numN > 1)
- {
- Random numRandom = new Random();
- bool [] arrBool = new bool [numN + 1];
- int index = 0;
- checked
- {
- for (int i = 0; i < numN; i++)
- {
- int numNext = numRandom.Next(1, ((int)numN + 1));
- index = numNext;
- if (numNext == index && arrBool[index])
- {
- i--;
- continue;
- }
- else
- {
- arrBool [index] = true;
- Console.Write("{0} ", numNext);
- }
- }
- }
- Console.WriteLine();
- }
- else
- {
- Console.WriteLine("Error - Invalid Number !!!");
- }
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement