Hello GHMON,

You have received several answers to your question. Just for fun another approach.

Initially you create an array of 1 - 1000 values. Then you use the random function to choose an element from this array and the same time when you choose an element you remove it from the array to make sure on your final array you will not have it again :)

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @original = 1 .. 1000; # print Dumper \@array; my @array; push @array, splice(@original, rand @original, 1) for (1 .. 100 ); print Dumper \@array; __END__ $VAR1 = [ 848, 909, 62, . . . etc

If you really want to push things even more (not that makes a difference but just for fun). You can shuffle the original array before you choose the value randomly:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use List::Util qw(shuffle); my @original = 1 .. 1000; # print Dumper \@array; @original = shuffle(@original); my @array; push @array, splice(@original, rand @original, 1) for (1 .. 100 ); print Dumper \@array; __END__ $VAR1 = [ 319, 793, 69, 571, . . . etc

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Make random numbers by thanos1983
in thread Make random numbers by GHMON

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.