Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by tedrek (Pilgrim)
on Apr 27, 2004 at 19:06 UTC ( #348606=note: print w/replies, xml ) Need Help??


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

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+@_)]; }
  • Comment on Re: Re: Re: What is the limit of random number that can be selected
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Re: What is the limit of random number that can be selected
by Sameet (Beadle) on Apr 29, 2004 at 09:09 UTC
    That was really helpful. I am looking into the matter now. Thank you for your help.
    Sameet

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2021-09-19 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?