perl -le '@l=sort{rand$_<=>rand$_}(1..10);print for@l[0..2]'
In older Perls, it's not garanteed to give any meaningful results - in fact, perl might as well segfault. In modern Perls, about all that's garanteed is that perl won't segfault, and perl won't internally get corrupted. I'm not at all convinced that the above code produces fair results. Here's a test with a smaller array that strongly suggests your algorithm isn't fair:
#!/usr/bin/perl use strict; use warnings; no warnings qw /syntax/; my @array = (1 .. 4); my %count; my $mult = 10_000; for (1 .. 24 * $mult) { my @t = sort {rand 1 <=> rand 1} @array; $count {"@t"} ++; } foreach my $key (sort keys %count) { printf "%5d: %s\n" => $count {$key}, $key } __END__ 15063: 1 2 3 4 15069: 1 2 4 3 7419: 1 3 2 4 7615: 1 3 4 2 7602: 1 4 2 3 7606: 1 4 3 2 14978: 2 1 3 4 14923: 2 1 4 3 7497: 2 3 1 4 7460: 2 3 4 1 7558: 2 4 1 3 7401: 2 4 3 1 7485: 3 1 2 4 7484: 3 1 4 2 7585: 3 2 1 4 7577: 3 2 4 1 14876: 3 4 1 2 14968: 3 4 2 1 7467: 4 1 2 3 7544: 4 1 3 2 7461: 4 2 1 3 7477: 4 2 3 1 14853: 4 3 1 2 15032: 4 3 2 1

Abigail


In reply to Re: Select three random numbers between 1..10 by Abigail-II
in thread Select three random numbers between 1..10 by Perl_User

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.