Skip to content

Instantly share code, notes, and snippets.

@kyzalex
Last active March 27, 2024 15:16
Show Gist options
  • Save kyzalex/e0a02eb4ac8f10caa0641454df624b0c to your computer and use it in GitHub Desktop.
Save kyzalex/e0a02eb4ac8f10caa0641454df624b0c to your computer and use it in GitHub Desktop.
Канзас сити шафл
internal class Program
{
static void Main(string[] args)
{
int[] array = new int[10];
for (int i = 0; i < array.Length; i++)
{
array[i] = i;
}
PrintArray(array);
Shuffle(array);
Console.WriteLine();
PrintArray(array);
Console.ReadKey();
}
static void PrintArray(int[] array)
{
for (int i = 0; i < array.Length; i++)
{
Console.Write(array[i] + " ");
}
}
static void Shuffle(int[] array)
{
Random random = new Random();
int temp;
for (int i = 0; i < array.Length; i++)
{
int randomIndex = random.Next(array.Length);
temp = array[i];
array[i] = array[randomIndex];
array[randomIndex] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment