in reply to 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

Can you show my via an example. Actually, i am very bad at coding!!!
thanks
--Sameet
  • Comment on Re: Re: What is the limit of random number that can be selected

Replies are listed 'Best First'.
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

    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.
      Sameet