On production server:
"KYK_iphone3.jpg".hash.abs%1000
=> 908
But on staging server:
"KYK_iphone3.jpg".hash.abs%1000
=> 740
The two hashes do not match. Can you please give me your ideas on what to do in this situation?
Ruby's default hashing is not guaranteed to be consistent across implementations. You should use a standardized hashing algorithm such as MD5, SHA1 or similar, if you require consistent hashes.
EDIT: On further investigation, it turns out it is not even consistent across different processes:
$ irb
> "abc".hash
=> 3669021835949727595
> exit
$ irb
> "abc".hash
=> 2091809102525897616
It appears this might be an intended security feature inherited from Perl to protect against algorithmic complexity attacks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With