Skip to content

Instantly share code, notes, and snippets.

@StrikerXx798
Last active April 19, 2025 14:00
Show Gist options
  • Save StrikerXx798/3209658acc1d63c197e3b54992a39773 to your computer and use it in GitHub Desktop.
Save StrikerXx798/3209658acc1d63c197e3b54992a39773 to your computer and use it in GitHub Desktop.
ДЗ: Канзас сити шафл
using System;
using System.Text;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
Console.InputEncoding = Encoding.Unicode;
Console.OutputEncoding = Encoding.Unicode;
int[] ints = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
DrawArray(ints, "До перемешивания:");
ShuffleArray(ints);
DrawArray(ints, "После перемешивания:");
}
static void ShuffleArray(int[] array)
{
Random random = new Random();
int arrayLength = array.Length;
for (int i = arrayLength - 1; i >= 0; i--)
{
int randomIndex = random.Next(0, arrayLength);
int temp = array[i];
array[i] = array[randomIndex];
array[randomIndex] = temp;
}
}
static void DrawArray(int[] array, string text)
{
Console.WriteLine(text);
foreach (int i in array)
{
Console.Write(i + " ");
}
Console.WriteLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment