in reply to Perl hashes and non-determinism
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: $!" ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl hashes and non-determinism
by Ratazong (Monsignor) on Nov 21, 2025 at 11:41 UTC |