NikaBang

ДЗ: Канзас сити шафл

Oct 24th, 2025 (edited)
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | Gaming | 0 0
  1. using System;
  2.  
  3. internal class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         Random random = new Random();
  8.  
  9.         int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  10.  
  11.         Console.Write("Изначальный массив: ");
  12.         Console.WriteLine(string.Join(" ", numbers));
  13.  
  14.         Shuffle(numbers);
  15.  
  16.         Console.Write("Перемешанный массив: ");
  17.         Console.WriteLine(string.Join(" ", numbers));
  18.  
  19.         random.Shuffle(numbers);
  20.  
  21.         Console.Write("Перемешанный массив встроенным методом: ");
  22.         Console.WriteLine(string.Join(" ", numbers));
  23.         Console.ReadKey();
  24.     }
  25.  
  26.     static void Shuffle(int[] array)
  27.     {
  28.         Random random = new Random();
  29.  
  30.         for (int i = array.Length - 1; i > 0; i--)
  31.         {
  32.             int index = random.Next(i + 1);
  33.             (array[i], array[index]) = (array[index], array[i]);
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment