Similar to srand()?

Env var PERL_HASH_SEED would be the equivalent. Setting it will use the provided value as a seed.

$ demo() { perl -e' use v5.18; my %h; ++$h{ $_ } for "a".."z"; say keys %h; ' } $ demo nylxbvceamuszdrotqfgpwikhj $ demo ahedybntzwgmpulqijkrsxfvoc $ PERL_HASH_SEED=0 demo udbaxqhcnmskzeiwryvlftojgp $ PERL_HASH_SEED=0 demo udbaxqhcnmskzeiwryvlftojgp $ PERL_HASH_SEED=0x0123456789ABCDEf demo lfojtgpzekwriyvchmnsuadbqx $ PERL_HASH_SEED=0x0123456789ABCDEF demo lfojtgpzekwriyvchmnsuadbqx

Even with PERL_HASH_SEED=0 (which is documented to remove the random perturbations), the order is obscure, and the order of the keys can change as you add new elements. But the order and changes to it will be the same every run (as long as the program is run on similar-enough builds of Perl).

Note that there are denial-of-service risks associated with removing the random perturbations when the keys are controlled by an external actor. This probably doesn't matter for your contest.

The env var needs to be set before perl starts, but you can use bootstrapping to achieve this if you can't control that aspect of the contest's environment.

BEGIN { return if exists( $ENV{ PERL_HASH_SEED } ); $ENV{ PERL_HASH_SEED } = "0"; exec( $^X, "--", $0, @ARGV ) or die( "exec: $!" ); }

In reply to Re: Perl hashes and non-determinism by ikegami
in thread Perl hashes and non-determinism by Ratazong

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.