Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace C_sharp_Light
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> array = new List<int>();
- int sizeArray = 10;
- Console.WriteLine("Первоначальный массив");
- for (int i = 0; i < sizeArray; i++)
- {
- array.Add(i);
- Console.Write($"{array[i]} ");
- }
- Console.WriteLine("\nПеремешанный массив");
- array = Shuffle(array);
- for (int i = 0; i < array.Count; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- Console.ReadKey();
- }
- static List<int> Shuffle(List<int> mainArray)
- {
- List<int> tempArray = new List<int>(mainArray.Count);
- Random rand = new Random();
- while (mainArray.Count > 0)
- {
- int i = rand.Next(0, mainArray.Count);
- tempArray.Add(mainArray[i]);
- mainArray.RemoveAt(i);
- }
- return tempArray;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement