Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have generated 10 random numbers from 1 to 1000. How do I now sort them using arrays in an ascending order, regardless of what numbers are generated each time the program is run?
#!/usr/bin/perl # Generate 10 random numbers between 1 and 1000 for ($x=0;$x<10;$x++) { print int (rand(1000) + 1) ."\t"; if ($x%5==0) { print "\n"; } } END;

janitored by ybiC: Balanced <code> tags around codeblock

Replies are listed 'Best First'.
Re: array in ascending order
by duff (Parson) on May 21, 2004 at 18:03 UTC
    You would place the random numbers in an array and use sort and perhaps reverse

      Not reverse. You should just sort the list that way in the first place. Unless you need two lists to handle both directions.

      ----
      send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.

        Sure, but reverse is something handy to know exists :)
Re: array in ascending order
by pbeckingham (Parson) on May 21, 2004 at 18:27 UTC

    Do what you were advised to do before, and sort the reuslts.

    my @a = sort {$a <=> $b} map {int (rand (1000) + 1)} 1..10;