Advertisement
pol9na

Untitled

Mar 25th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 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. namespace Study
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  13.             shuffleArray(array);
  14.  
  15.             for (int j = 0; j < array.Length; j++)
  16.             {
  17.                 Console.WriteLine(array[j]);
  18.             }
  19.             Console.ReadKey();
  20.         }
  21.         public static void shuffleArray(int[] firstArray)
  22.         {
  23.             int lengthArray = firstArray.Length;
  24.             Random rand = new Random();
  25.  
  26.             for (int i = 0; i < lengthArray; i++)
  27.             {
  28.                 swap(firstArray, i, i + rand.Next(lengthArray - i));
  29.             }
  30.         }
  31.         public static void swap(int[] array, int firstArray, int secondArray)
  32.         {
  33.             int temp = array[firstArray];
  34.             array[firstArray] = array[secondArray];
  35.             array[secondArray] = temp;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement