View difference between Paste ID: w8FXEipw and C26sWULh
SHOW: | | - or go back to the newest paste.
1
using System;
2
3
namespace C_sharp_Light
4
{
5
    class Program
6
    {
7
        static void Main(string[] args)
8
        {
9-
            
9+
            List<int> array = new List<int>();
10
            int sizeArray = 10;
11
12
            Console.WriteLine("Первоначальный массив");
13
            for (int i = 0; i < sizeArray; i++)
14
            {
15
                array.Add(i);
16
                Console.Write($"{array[i]} ");
17
            }
18
19
            Console.WriteLine("\nПеремешанный массив");
20
            array = Shuffle(array);
21
            for (int i = 0; i < array.Count; i++)
22
            {
23
                Console.Write(array[i] + " ");
24
            }
25
            Console.WriteLine();
26
            Console.ReadKey();
27
        }
28
        static List<int> Shuffle(List<int> mainArray)
29
        {
30
            List<int> tempArray = new List<int>(mainArray.Count);
31
            Random rand = new Random();
32
33
            while (mainArray.Count > 0)
34
            {
35
                int i = rand.Next(0, mainArray.Count);
36
                tempArray.Add(mainArray[i]);
37
                mainArray.RemoveAt(i);
38
            }
39
            return tempArray;
40
        }
41
    }
42
}