Look again. Duplicate letters work.

However, ActivePerl v5.6.1 build 633 actually returns unshuffled results for "rotohotel", "r1t2h3tel" and "r1t2h3tels"!! Nothing guarantees that order is lost in a hash.

May I recommend a variation:

$_='rotohotel'; my $len; my %f=map {rand() . '|' . $len++ => $_} split //; print join('', values %f), "\n";

It seems values() is implemented as map { $hash{$_} } sort keys %hash) on this build!!

Update: ok, so it's not always sorted:

%hash = map { $_ => $_ } qw(m i f e z l x v b r d o h y j q s t k n g +c a p w u); print(join('', values(%hash)), "\n"); # prints: abcdefghijklmnopqrstuvwxyz SORTED %hash = map { $_ => $_ } qw(m i f e z l x 2 v b r d o h y j q s t k n +g c a p w u); print(join('', values(%hash)), "\n"); # prints: abcdefghijklmnop2qrstuvwxyz NOT SORTED %hash = map { $_ => $_ } qw(6 3 5 0 1 2 9 8 7 4); print(join('', values(%hash)), "\n"); # prints: 0123456789 SORTED %hash = map { $_ => $_ } qw(6 3 5 0 34 1 2 33 9 8 7 4); print(join(':', values(%hash)), "\n"); # prints: 0:1:2:3:4:5:6:7:8:9:33:34 SORTED %hash = map { $_ => $_ } qw(a aaaaaaa aaaa aaa aa aaaaa aaaaaaaaaa); print(join(':', values(%hash)), "\n"); # prints: aa:aaaaaaa:a:aaaaaaaaaa:aaaaa:aaaa:aaa NOT SORTED

In reply to Re^3: Randomize word by ikegami
in thread Randomize word by vikee

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.