Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: What is the limit of random number that can be selected

by astaines (Curate)
on Apr 24, 2004 at 19:41 UTC ( #347879=note: print w/replies, xml ) Need Help??

in reply to What is the limit of random number that can be selected

Few comments - your inner loop could be replaced by a hash look up. Put the number of contigs on each chromosome into a hash indexed by chromosome, and pull the limits of the loop from there. This scales better, and is far easier to extend to other organisms.

Also, generating very large random numbers is always difficult. You are very likely to run across machine and architecture specific problems.A simpler solution is to generate two random numbers, one which selects a segment of the database, array or whatever you're getting your stuff from, and a second which selects the specific item.

Whether this is what you want depends on your application. Go ask your friendly statistician.

-- Anthony Staines
  • Comment on Re: What is the limit of random number that can be selected

Replies are listed 'Best First'.
Re: Re: What is the limit of random number that can be selected
by Sameet (Beadle) on Apr 25, 2004 at 08:42 UTC
    Can you show my via an example. Actually, i am very bad at coding!!!

      Heres how I would code what you have already:

      #!/usr/bin/perl use strict; use warnings; #use BeginPerlBioinfo; srand($$|time); my $data = { 'Homo Sapien' => { Chromosomes => { (map { $_ => {Contigs => 25} } (1..22, qw/X Y/)), # Auto g +en 1 => {Contigs => 30}, # Override these two.. 2 => {Contigs => 28}, }, }, }; # This program will download the sequences from a given organism my $organism = ask('Which organism would you like to download the '. 'sequences from?'); #my $organism = 'Homo Sapien'; my $number = ask("How many sequences do you want to generate?"); #my $number = 10; if (exists $data->{$organism}) { for (1..$number) { my $chromosome = random_element(keys%{$data->{$organism}{Chrom +osomes}}); print " Chromosome '$chromosome' \n"; my $contig = random_element( (1..$data->{$organism}{Chromosomes}{$chromosome}{ +Contigs}) ); print " Contig '$contig' \n"; } } else { print "I don't know anything about organism: '$organism'\n"; } exit; ################ # ############## # ask # # Sub which asks a given question and returns the chomped input from t +he user sub ask { my $query = shift; print $query, ":\n"; my $answer = <STDIN>; chomp $answer; return $answer; } # random_element # # Sub routine that picks up random element from a given array sub random_element{ # I think there's a problem with the randomness of this return $_[int rand(0+@_)]; }
        That was really helpful. I am looking into the matter now. Thank you for your help.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://347879]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2020-07-06 11:53 GMT
Find Nodes?
    Voting Booth?

    No recent polls found