Advertisement
Guest User

4.7

a guest
May 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 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 ConsoleApp3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  14.             Console.Write("Дан массив: ");
  15.             for (int i = 0; i < array.Length; i++)
  16.             {
  17.                 Console.Write(array[i] + " ");
  18.             }
  19.             Console.WriteLine();
  20.             Shuffle(array);
  21.             Console.Write("Канзас сити шафл: ");
  22.             for (int i=0;i<array.Length; i++)
  23.             {
  24.                 Console.Write(array[i] + " ");
  25.             }
  26.             Console.WriteLine();
  27.             Console.ReadKey();
  28.            
  29.  
  30.         }
  31.         static void Shuffle(int[] array)
  32.         {
  33.            
  34.             Random rnd = new Random();
  35.             for (int i = array.Length - 1; i >= 1; i--)
  36.             {
  37.                 int j = rnd.Next(i + 1);                
  38.                 var temp = array[j];
  39.                 array[j] = array[i];
  40.                 array[i] = temp;
  41.             }
  42.         }
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement