2008/2/6, Tim Pease <tim.pease / gmail.com>:
>
> On Feb 5, 2008, at 4:04 PM, Clifford Heath wrote:
>
> > Tim Pease wrote:
> >> Should this output the same integer value on all platforms where
> >> Ruby  can run?
> >
> > Perhaps, but if you read the below, you'll see why you should never
> > rely
> > on it.
> >
> >> It appears not!  So, any suggestions on generating an ID number for
> >> an  object that is unique yet consistent across different
> >> platforms?  I'd  like to have some method that I could call on an
> >> object that would  return a reproducible value that would uniquely
> >> identify that object.
> >
> > That's not possible. There is more entropy in an arbitrary object than
> > can be represented in a FixNum. Basic coding theory stuff. If it was
> > possible, then you could code all the data in all the databases in the
> > world into a single Fixnum :-).
>
> Darn information theory!  I just need a fixnum. The number of objects
> we are creating is pretty tiny -- maybe 100.
>
> I was quite surprised that the Ruby "hash" method is not consistent
> across platforms. The solution is to roll my own hash function that
> produces consistent results.

A regular hash function is a bad candidate for a unique id anyway.
I'd rather use a MD5 or something like that.  If your strings are
reasonably short you can as well convert them to Fixnums but then
again: why bother and not directly use the string?

>  Just wondering about the more general
> questions regarding the built in hash function.

There is no need for a hash function to be consistent across
platforms.  Why should it?

Kind regards

robert

-- 
use.inject do |as, often| as.you_can - without end