using System;
using System.Collections.Generic;
public class Test
{
static Random random = new Random();
public static List<int> GenerateRandom(int count)
{
// generate count random values.
HashSet<int> candidates = new HashSet<int>();
while (candidates.Count < count)
{
// May strike a duplicate.
candidates.Add(random.Next());
}
// load them in to a list.
List<int> result = new List<int>();
result.AddRange(candidates);
// shuffle the results:
int i = result.Count;
while (i > 1)
{
i--;
int k = random.Next(i + 1);
int value = result[k];
result[k] = result[i];
result[i] = value;
}
return result;
}
public static void Main()
{
List<int> vals = GenerateRandom(10);
Console.WriteLine("Result: " + vals.Count);
vals.ForEach(Console.WriteLine);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXN0YXRpYyBSYW5kb20gcmFuZG9tID0gbmV3IFJhbmRvbSgpOwoJCglwdWJsaWMgc3RhdGljIExpc3Q8aW50PiBHZW5lcmF0ZVJhbmRvbShpbnQgY291bnQpCgl7CgkJLy8gZ2VuZXJhdGUgY291bnQgcmFuZG9tIHZhbHVlcy4KCQlIYXNoU2V0PGludD4gY2FuZGlkYXRlcyA9IG5ldyBIYXNoU2V0PGludD4oKTsKCQl3aGlsZSAoY2FuZGlkYXRlcy5Db3VudCA8IGNvdW50KQoJCXsKCQkJLy8gTWF5IHN0cmlrZSBhIGR1cGxpY2F0ZS4KCQkJY2FuZGlkYXRlcy5BZGQocmFuZG9tLk5leHQoKSk7CgkJfQoJCQoJCS8vIGxvYWQgdGhlbSBpbiB0byBhIGxpc3QuCgkJTGlzdDxpbnQ+IHJlc3VsdCA9IG5ldyBMaXN0PGludD4oKTsKCQlyZXN1bHQuQWRkUmFuZ2UoY2FuZGlkYXRlcyk7CgkJCgkJLy8gc2h1ZmZsZSB0aGUgcmVzdWx0czoKCQlpbnQgaSA9IHJlc3VsdC5Db3VudDsgIAogICAgICAgIHdoaWxlIChpID4gMSkKICAgICAgICB7ICAKICAgICAgICAgICAgaS0tOyA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