Advertisement
NikaBang

Канзас сити шафл

Oct 14th, 2024 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System;
  2.  
  3. internal class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  8.  
  9.         OutputArray(numbers);
  10.  
  11.         Console.WriteLine();
  12.  
  13.         Shuffle(numbers);
  14.         OutputArray(numbers);
  15.  
  16.         Console.ReadKey();
  17.     }
  18.  
  19.     static void Shuffle(int[] array)
  20.     {
  21.         Random random = new Random();
  22.  
  23.         for (int i = array.Length - 1; i >= 1; i--)
  24.         {
  25.             int index = random.Next(i + 1);
  26.             int temp = array[index];
  27.             array[index] = array[i];
  28.             array[i] = temp;
  29.         }
  30.     }
  31.  
  32.     static void OutputArray(int[] array)
  33.     {
  34.         foreach (int number in array)
  35.         {
  36.             Console.Write(number + " ");
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement