Could not understand what u mean ???
I made several changes on your code:
using System;
using System.Collecti ons;
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.ContainsK ey(hash))
{
map[hash]=d;
distinct++;
if (distinct % 1000==0)
{
//Console.WriteLi ne (distinct);
}
}
else
{
if (((double)map[hash])!=d)
{
same++;
Console.WriteLi ne("{0}\t{1}",d ,map[hash]);
}
}
}
}
}
--
Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Yunus Emre ALPÖZEN [MCAD.NET] <ye***@msakadem ik.net> wrote:
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*10 24
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.Collecti ons;
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.ContainsK ey(hash))
{
map[hash]=hash;
distinct++;
if (distinct % 1000==0)
{
Console.WriteLi ne (distinct);
}
}
}
}
}
It doesn't take it long to go over the number of distinct values you
claim.
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too