LeRoY_Go

Untitled

Feb 2nd, 2022
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2.  
  3. namespace C_Sharp_Junior
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  10.             Shuffle(array);
  11.         }
  12.  
  13.         static void Shuffle(int[] array)
  14.         {
  15.             string userInput = "";
  16.             Random random = new Random();
  17.             while (userInput != "exit")
  18.             {
  19.                 for (int i = 0; i < array.Length; i++)
  20.                 {
  21.                     int randomElement = random.Next(i);
  22.                     int indexElement = array[i];
  23.                     array[i] = array[randomElement];
  24.                     array[randomElement] = indexElement;
  25.                     Console.Write(array[randomElement] + " ");
  26.                 }
  27.                 userInput = Console.ReadLine();
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment