Advertisement
pol9na

Untitled

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