Hi,
is it possible to select a random number from an array containing 181014922 elements or even higher number of elements, something like 3,020,300,000. can PERL do that, or it has to be done in a complicated manner. regards sameet.

Regarding this I have actually written a longish program, I actually need to add one more nested loop in each elsif loop, I am pasting the code for reference. If there is a easier way out Please tell me

#!/usr/bin/perl use strict; #use warnings; use BeginPerlBioinfo; srand ($$|time); my $contig; # This program will download the sequences from a given organism my $organism; print "Give the organism from where you want to download the sequences +:\n"; $organism = <STDIN>; chomp $organism; #print "Give number of sequences to be generated"; #print "\n"; my $number = 10; #chomp $number; my @numbers = (1 .. $number); foreach my $numbers(@numbers){ if ($organism eq 'Homo Sapien'){ my @chromosomes = qw\1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 + 18 19 20 21 22 'X' 'Y'\; # pick a random chromosome from the chromosomes in humans my $chromosome = random_element(@chromosomes); #my $contig; print "Chromosome $chromosome\n"; # pick up a contig randomly from the number of contigs present + in each given chromosome # This is one more loop if ( my $chomosome eq '1'){ my @contigs = (1 .. 30); my $contig = random_element(@contigs); } elsif ($chromosome eq '2'){ my @contigs = (1 .. 28); my $contig = random_element(@contigs); } elsif ($chromosome eq '3'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '4'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '5'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '6'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '7'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '8'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '9'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '10'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '11'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '12'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '13'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '14'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '15'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '16'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '17'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '18'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '19'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '20'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '21'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq '22'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } elsif ($chromosome eq 'X'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs) } elsif ($chromosome eq 'Y'){ my @contigs = (1 .. 25); my $contig = random_element(@contigs); } print " Contig $contig \n"; } } ################ # ############## # random_element # # Sub routine thta picks up random element from a given array sub random_element{ my @array = @_; return $array [rand @array]; }

janitored by ybiC: Balanced <readmore> tags around longish codeblock, especially for frontpaged root node. Also wee tiny format tweaks for legibility.


In reply to What is the limit of random number that can be selected by Sameet

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.