The order is not random in a cryptographic sense. It simply has no bearing on the order in which elements were added and no apparent bearing on the keys. The order in which keys, values and each return their results is based on the internal format of the hash.

The internal format of the hash does not change if no keys are added to the hash, so the order is guaranteed not change if no change is made to the hash. @hash1{keys %hash2} = values %hash2; will work, for example.

In fact, if you repeat the steps you used to create a hash to create a new hash in the same process, the new hash should be in the same order.

Anyway, the point is that "random" is not a goal, but a possible side-effect.

Unrelated, a security measure has been in place since Perl 5.8.1 to randomize the order between perl processes. That means if repeat the steps you used to create a hash to create a new hash in the different process, the new hash may be in a different order.

So your test fails (by not returning failures) for two reasons:
An unchanged hash doesn't change its order.
You only have one process involved, so the security measure isn't applicable.


In reply to Re: Deterministic or keys in random order by ikegami
in thread Deterministic or keys in random order by andreas1234567

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.