AlexRaynor

4.7 Shuffle

Sep 22nd, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 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 ConsoleApp20
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] Array = { 1, 2, 3, 4, 5 };
  14.             Shuffle(Array);
  15.             for (int i = 0; i < Array.Length; i++)
  16.             {
  17.                 Console.WriteLine(Array[i]);
  18.             }
  19.  
  20.         }
  21.  
  22.  
  23.         static int[] Shuffle(int[] Array)
  24.         {
  25.  
  26.  
  27.             Random rnd = new Random();
  28.  
  29.             int[]newArray = Array.OrderBy(s => rnd.Next()).ToArray();
  30.  
  31.             for (int i = 0; i < Array.Length; i++)
  32.             {
  33.                 Array[i] = newArray[i];
  34.             }
  35.  
  36.             Array = newArray;
  37.  
  38.             return Array;
  39.  
  40.         }
  41.  
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment