Skip to content

Instantly share code, notes, and snippets.

@Dnk095
Last active May 14, 2024 12:40
Show Gist options
  • Save Dnk095/dd5abf267990c6622a8d1ba2cce805ea to your computer and use it in GitHub Desktop.
Save Dnk095/dd5abf267990c6622a8d1ba2cce805ea to your computer and use it in GitHub Desktop.
using System;
namespace _4_3
{
internal class Program
{
static void Main()
{
int arrayLength = 10;
int[] arrayForShuffle = new int[arrayLength];
for (int i = 0; i < arrayLength; i++)
{
arrayForShuffle[i] = i;
}
Console.WriteLine("Стартовый массив: ");
WriteArray(arrayForShuffle);
Shufle(arrayForShuffle);
Console.WriteLine("\nМассив после перемешивания");
WriteArray(arrayForShuffle);
}
static void Shufle(int[] array)
{
int temporarilyNumber;
for (int i = 0; i < array.Length; i++)
{
Random random = new Random();
int randomIndex = random.Next(0, array.Length);
temporarilyNumber = array[i];
array[i] = array[randomIndex];
array[randomIndex] = temporarilyNumber;
}
}
static void WriteArray(int[] array)
{
for (int i = 0; i < array.Length; i++)
{
Console.Write(array[i] + " ");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment