Could not understand what u mean ???
I made several changes on your code:
using System;
using System.Collections;
class Test
{
static void Main()
{
Hashtable map = new Hashtable();
Random rng = new Random();
int distinct = 0;
int same = 0;
while (true)
{
double d = rng.Next();
int hash = d.GetHashCode();
if (!map.ContainsKey(hash))
{
map[hash]=d;
distinct++;
if (distinct % 1000==0)
{
//Console.WriteLine (distinct);
}
}
else
{
if (((double)map[hash])!=d)
{
same++;
Console.WriteLine("{0}\t{1}",d,map[hash]);
}
}
}
}
}
--
Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET
Yunus Emre ALPÖZEN said:
hi,
every time it calculates 1072693248 for x1 and x2. but x2 has a special
value.
For instance;
x2+1.0= ?
answer is quite surprising: 1.0
for x2=2.0 it calculates 1073741824
difference it is 1048576=1024*1024
there are 1048576 distinct values. Hashing function simply calculates in
this way...
That's quite a leap of logic there...
Here's a counterexample - this class just generates random doubles and
checks whether or not the hashcode has already been seen:
using System;
using System.Collections;
class Test
{
static void Main()
{
Hashtable map = new Hashtable();
Random rng = new Random();
int distinct = 0;
while (true)
{
double d = rng.Next();
int hash = d.GetHashCode();
if (!map.ContainsKey(hash))
{
map[hash]=hash;
distinct++;
if (distinct % 1000==0)
{
Console.WriteLine (distinct);
}
}
}
}
}
It doesn't take it long to go over the number of distinct values you
claim.