Static list<int> Given50randomnumbers ()
{
list<int> intlist = new list<int> ();
for (int i=1;i<=50;i++)
{
Intlist.add (i);
}
if (intlist.count>0)
{
return intlist;
}
return null;
}
static void Main (string[] args)
{
list<int> intlist = Given50randomnumbers ();
list<int> targetlist = new list<int> ();
list<int> distinctlist = new list<int> ();
Do
{
Random rnd = new Random ();
int x = rnd. Next (0, 50);
if (!targetlist.contains (Intlist[x]))
{
Targetlist.add (Intlist[x]);
}
}
while (targetlist.count! = 50);
Distinctlist = Targetlist.distinct<int> (). ToList ();
Console.WriteLine ("The Count of Distinctlist is: {0}", Distinctlist.count);
foreach (Var a in targetlist)
{
System.Diagnostics.Debug.WriteLine (a);
Console.WriteLine (a);
}
Console.ReadLine ();
}
30
21st
39
7
49
17
9
27
45
37
5
23
14
32
24
42
10
2
20
38
47
25
35
3
13
4
22
40
50
18
28
15
33
43
12
48
8
36
46
1
11
29
16
26
44
31
41
19
6
34
C # Random Draw 50 Random code does not repeat