From: chr_news@... (chr_news@...) Date: 2001-12-12T02:43:22+09:00 Subject: [ruby-talk:28252] Re: Hash.keys Q > Yes, the order of the keys in an Hash depend of the hash function. For > example in your case, the order is given by The order of the keys does not depend on the hash function - however for small hashes there is a statistical trend. I get the output order reversal occurred 484 out of 100000 times order reversal occurred 0 out of 100000 times when I run the following script ----------- class Reversal def self.count1 m normal = 0 reverse = 0 m.times do |i| e = new o = new hsh = {e => o, o => e} swap_hsh = {o => e, e => o} if (hsh.keys == swap_hsh.keys) normal+=1 else reverse+=1 end end puts "order reversal occurred #{reverse} out of #{m} times" end def self.count2 m normal = 0 reverse = 0 e = new o = new m.times do |i| hsh = {e => o, o => e} swap_hsh = {o => e, e => o} if (hsh.keys == swap_hsh.keys) normal+=1 else reverse+=1 end end puts "order reversal occurred #{reverse} out of #{m} times" end end Reversal.count1 10**5 Reversal.count2 10**5 ----------- /Christoph