Advertisement
OwlyOwl

kansas...

Mar 28th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp7
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int arrayLength = 10;
  10.             Random rand = new Random();
  11.             int[] array = new int[arrayLength];
  12.             for (int i = 0; i < array.Length; i++)
  13.             {
  14.                 array[i] = rand.Next(0, 50);
  15.                 Console.WriteLine(array[i] + " ");
  16.             }
  17.             ShuffleArray(array, arrayLength);
  18.             Console.WriteLine("After shuffle:");
  19.             for (int j = 0; j < array.Length; j++)
  20.             {
  21.                 Console.WriteLine(array[j] + " ");
  22.             }
  23.         }
  24.         static int[] ShuffleArray(int[] array, int length)
  25.         {
  26.             int tempNum;
  27.             Random rng = new Random();
  28.             for (int j = 0; j < length; j++)
  29.             {
  30.                 int randOrder = rng.Next(0, length);
  31.                 tempNum = array[j];
  32.                 array[j] = array[randOrder];
  33.                 array[randOrder] = tempNum;
  34.             }
  35.             return array;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement