Fixnum #hash all odd or all even

(0…1000000).map { |i| i.hash % 2 }.uniq

The above code will either return [1] or [0] (it changes when you close
and restart IRB, though a return of [0] seems far more common than [1]).

Can confirm this to happen on Ruby versions:

ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin12.4.0]
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.5.0]
ruby 2.1.0dev (2013-09-22 trunk 43011) [x86_64-darwin12.5.0]

Mac OSX 10.8.5.

Just strikes me as a bit strange that Fixnums would return either all
odd or all even hash values, halving the potential range of hash values
:confused: Is this intentional? If so, how come?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs