using System;
using System.Collections.Generic;
public class Test
{
static Random random = new Random();
public static List<int> GenerateRandom(int count)
{
List<int> result = new List<int>(count);
// generate count random values.
HashSet<int> candidates = new HashSet<int>();
// top will overflow to Int32.MinValue at the end of the loop
for (Int32 top = Int32.MaxValue - count + 1; top > 0; top++)
{
// May strike a duplicate.
int value = random.Next(top);
if (candidates.Add(value))
{
result.Add(value);
}
else
{
result.Add(top);
candidates.Add(top);
}
}
return result;
}
public static void Main()
{
List<int> vals = GenerateRandom(10);
Console.WriteLine("Result: " + vals.Count);
vals.ForEach(Console.WriteLine);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXN0YXRpYyBSYW5kb20gcmFuZG9tID0gbmV3IFJhbmRvbSgpOwoJCglwdWJsaWMgc3RhdGljIExpc3Q8aW50PiBHZW5lcmF0ZVJhbmRvbShpbnQgY291bnQpCgl7CgkJTGlzdDxpbnQ+IHJlc3VsdCA9IG5ldyBMaXN0PGludD4oY291bnQpOwoJCQoJCS8vIGdlbmVyYXRlIGNvdW50IHJhbmRvbSB2YWx1ZXMuCgkJSGFzaFNldDxpbnQ+IGNhbmRpZGF0ZXMgPSBuZXcgSGFzaFNldDxpbnQ+KCk7CgkJLy8gdG9wIHdpbGwgb3ZlcmZsb3cgdG8gSW50MzIuTWluVmFsdWUgYXQgdGhlIGVuZCBvZiB0aGUgbG9vcAoJCWZvciAoSW50MzIgdG9wID0gSW50MzIuTWF4VmFsdWUgLSBjb3VudCArIDE7IHRvcCA+IDA7IHRvcCsrKQoJCXsKCQkJLy8gTWF5IHN0cmlrZSBhIGR1cGxpY2F0ZS4KCQkJaW50IHZhbHVlID0gcmFuZG9tLk5leHQodG9wKTsKCQkJaWYgKGNhbmRpZGF0ZXMuQWRkKHZhbHVlKSkKCQkJewoJCQkJcmVzdWx0LkFkZCh2YWx1ZSk7CgkJCX0KCQkJZWxz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