private void Form1_Load(object sender, EventArgs e)
{
Hashtable ht = new Hashtable();
Random rm = new Random();
int RmNum = 10;
for (int i = 0; ht.Count < RmNum; i++)
{
Int64 nValue = GetNextInt64(1,999999999999);
if (!ht.ContainsValue(nValue) && nValue != 0)
{
ht.Add(nValue, nValue);
Console.WriteLine(nValue.ToString());
}
}
}
public long GetNextInt64(long low, long hi)
{
RNGCryptoServiceProvider _rng = new RNGCryptoServiceProvider();
if (low >= hi)
throw new ArgumentException("low must be < hi");
byte[] buf = new byte[8];
double num;
//Generate a random double
_rng.GetBytes(buf);
num = Math.Abs(BitConverter.ToDouble(buf, 0));
//We only use the decimal portion
num = num - Math.Truncate(num);
//Return a number within range
return (long)(num * ((double)hi - (double)low) + low);
}
|