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>();
// 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.
if (!candidates.Add(random.Next(top))) {
candidates.Add(top);
}
}
// 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);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXN0YXRpYyBSYW5kb20gcmFuZG9tID0gbmV3IFJhbmRvbSgpOwoJCglwdWJsaWMgc3RhdGljIExpc3Q8aW50PiBHZW5lcmF0ZVJhbmRvbShpbnQgY291bnQpCgl7CgkJLy8gZ2VuZXJhdGUgY291bnQgcmFuZG9tIHZhbHVlcy4KCQlIYXNoU2V0PGludD4gY2FuZGlkYXRlcyA9IG5ldyBIYXNoU2V0PGludD4oKTsKCQkvLyB0b3Agd2lsbCBvdmVyZmxvdyB0byBJbnQzMi5NaW5WYWx1ZSBhdCB0aGUgZW5kIG9mIHRoZSBsb29wCgkJZm9yIChJbnQzMiB0b3AgPSBJbnQzMi5NYXhWYWx1ZSAtIGNvdW50ICsgMTsgdG9wID4gMDsgdG9wKyspCgkJewoJCQkvLyBNYXkgc3RyaWtlIGEgZHVwbGljYXRlLgoJCQlpZiAoIWNhbmRpZGF0ZXMuQWRkKHJhbmRvbS5OZXh0KHRvcCkpKSB7CgkJCQljYW5kaWRhdGVzLkFkZCh0b3ApOwoJCQl9CgkJfQoJCQoJCS8vIGxvYWQgdGhlbSBpbi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