Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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]
[Marshall]: I also looked into PerlApp from Active State, but they don't sell their Dev Kit independent of a very expensive ($1,200) per year license anymore.
[Corion]: I would assume that the PE format hasn't changed that much since the days of yore, but it seems that I would be wrong in that assumption
[Marshall]: When I bought my copy 15+ years ago, it was just a couple hundred bucks.
[Marshall]: I looked at MS specs for PE format and I didn't see any changes in last decade, but evidenly that would be wrong.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2016-12-08 18:22 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (144 votes). Check out past polls.