-
-
Save Dnk095/dd5abf267990c6622a8d1ba2cce805ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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