Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Is it possible to "fix a seed" for hash?

by choroba (Archbishop)
on Mar 16, 2021 at 13:01 UTC ( #11129757=note: print w/replies, xml ) Need Help??

in reply to Is it possible to "fix a seed" for hash?

See PERL_HASH_SEED and other related variables in perlrun.

Scripts whose output depends on hashes are tested wrongly, because such scripts are buggy. If the order is important, sort the values, if it's not, use bag from Test::Deep in the tests.

Update: Similarly, for Test2 based testing, see Bag Builder in Test2::Tools::Compare.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Is it possible to "fix a seed" for hash?
by rsFalse (Chaplain) on Mar 22, 2021 at 10:13 UTC
    I tried to set PERL_HASH_SEED to 0, but I'm getting different outputs each time.
      I tried to set PERL_HASH_SEED to 0, but I'm getting different outputs each time.

      As choroba said, there are "other related variables" too, e.g. PERL_PERTURB_KEYS.

      However, since from your reply it seems like you're continuing down this route, let me state what I said here more directly: I can say with near certainty that you shouldn't be messing with these variables in the first place! Unless you can explain with certainty why you think you need these variables, I am certain we will be able to find a better (more robust, more portable, etc.) solution for you. So please explain your application some more, and the issue you are experiencing, and let's find a better solution than messing with PERL_HASH_SEED.

      Update: Rereading the node, that's a lot of certainty ;-)

      $ for i in {1..1000} ; do PERL_HASH_SEED=0 perl -lwe '%x = qw(a b c d +e f); print %x' ; done | sort | uniq -c 1000 cdefab
      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129757]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2022-09-29 11:14 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (125 votes). Check out past polls.