Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Clight_17_Shuffle
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool openMenu = true;
- int[,] massive = { { 1, 2, 3 }, { 1, 2, 1 }, { 1, 1, 1 } };
- while (openMenu == true)
- {
- Print(massive);
- Shuffle(massive);
- Console.ReadKey();
- Console.Clear();
- }
- }
- static void Shuffle(int[,] massive)
- {
- int[,] currentMassive = massive;
- int currentElement = 0;
- int randomI;
- int randomJ;
- Random random = new Random();
- for (int i = 0; i < currentMassive.GetLength(0); i++)
- {
- for (int j = 0; j < currentMassive.GetLength(1); j++)
- {
- currentElement = currentMassive[i, j];
- randomI = random.Next(0, currentMassive.GetLength(0));
- randomJ = random.Next(0, currentMassive.GetLength(1));
- currentMassive[i, j] = currentMassive[randomI, randomJ];
- currentMassive[randomI, randomJ] = currentElement;
- }
- Console.WriteLine();
- }
- massive = currentMassive;
- }
- static void Print(int[,] massive)
- {
- for (int i = 0; i < massive.GetLength(0); i++)
- {
- for (int j = 0; j < massive.GetLength(1); j++)
- {
- Console.Write($"{massive[i, j]} ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement