Just use a proper hash function (MD5, SHA1)?

On Friday, April 15, 2011, Roger Pack <rogerdpack2 / gmail.com> wrote:
> Hello all.
> I have a small program here that caches lookups. To do so it writes
> out a "unique" file based on the current ruby script, ex:
>
> filename = File.expand_path("~/#{$0.hash}")
>
> This worked great for looking up the file in 1.8.x, however in 1.9.x I
> see the following behavior:
>
> c:\dev>irb
>>> 'abc'.hash
> => -753597542
>>> 'abc'.hash
> => -753597542 # so it is consistent within the same process
>
> now run irb again:
>
> c:\dev>irb
>>> 'abc'.hash
> => 552773397 # different now!
>
> The hash values change each time you run a new process. I would have
> expected them to stay consistent so this is a bit surprising (even the
> hash values for things like an empty array are different now, too, and
> didn't used to be).
>
> Any feedback on this?
> Thanks.
> -r
>
>

-- 
// Magnus Holm