EN
C# / .NET - get random element from list
11 points
xxxxxxxxxx
1
List<int> list = new List<int>();
2
3
list.Add(11);
4
list.Add(22);
5
list.Add(33);
6
list.Add(44);
7
list.Add(55);
8
9
Random random = new Random();
10
11
for (int i = 0; i < 10; ++i)
12
{
13
int index = random.Next(list.Count);
14
15
Console.WriteLine(list[index]);
16
}
Output:
xxxxxxxxxx
1
33
2
44
3
11
4
55
5
55
6
55
7
22
8
11
9
11
10
11