tags:

views:

51

answers:

2

Is the value returned by ruby's #hash the same across interpreter instances?

For example, if I do "some string".hash, will I always get the same number even if run in different instances of the interpreter? If so, is this also true for all the builtin types (e.g. Hash, FixNum, etc).

+1  A: 

Not the same in different instances, at least with Ruby 1.9.1.

This link gives some further info...

It seems that they changed hash algorithm in 1.9 to a random seed-based one...

Mladen Jablanović
A: 

If you want to do something that you know will be the same across versions and objects try md5 or sha1.

require 'digest/md5'

Digest::MD5.hexdigest('some string')
Chuck Vose
SHA1 is probably a better deal than MD5 for reasons of being more modern, robust, and cryptographically appropriate.
tadman