Let me try and explain ... good monks...
my $Number_of_geographical_regions = 4; my $Number_of_generations = 3;
I would like to have a program that would produce an output like
Generation 1: Geographical regions: 2 3 1 4 Generation 2: Geographical regions: 4 2 3 1 Generation 3: Geographical regions: 1 4 3 2 <br>
.... where the order of the numbers is random.

I am mucking this up and need to start again. The code that I am mucking this up with looks something like:
my $nregions = 354; # 354; my $number_of_replicates = 3; my %seen; foreach my $generation (1..$number_of_replicates) { ## TEMP my @members = random_subset_X($nregions, $nregions );#$number_of_rep +licates ); # 5 element subsets, e.g. #### THIS BIT NEEDS SORTING OU +T my $key = join(" ", @members); # note: members already sorted redo if $seen{$key}; # make sure the subsets are unique $seen{$key} = 1; print "\n\nI'm about to enter the insert subset subroutine\n\n"; insert_subset($generation, @members); } ## TEMP sub random_subset_X { my ($n, $k) = @_; # $k member subset of 1..$n. # # $n is no. of re +gions, $k no. of replicates my %member; while ($k > 0) { my $x = int(rand()*$n)+1; # generates random number 1..$n. redo if $member{$x}; $member{$x} = 1; $k--; } continue { $k--; } sort keys %member; } sub insert_subset { my ( $generation, @members) = @_; for my $x (@members) { # $sth_insert_into_random->execute($generation, $x); print "$generation\t$x\n"; } }
However I am certain that I need to start again. Please can someone help me.

In reply to Coding random numbers by Win

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.