Bioperl: making a random sequence

Dave Campbell campbell@geospiza.com
Tue, 30 May 2000 09:52:18 -0700


I tried your code on my linux box ( running perl version 5.004_04 built
for i586-linux ).  I tried various invokations of srand() before the
calls to rand(), as described below:

First try, no call to srand():
Total:   1000000
Cumulative:      499996.214862632
Average:         0.499996214862632
A's:     250396
C's:     249497
G's:     249780
T's:     250327
 
 
 Second try, call srand():
Total:   1000000
Cumulative:      499919.488629005
Average:         0.499919488629005
A's:     249548
C's:     250914
G's:     249789
T's:     249749
 
 
Third try, call srand( time() ^ ($$ + ($$ << 15)) ): # As recommended in
the camel book.
Total:   1000000
Cumulative:      500087.825501791
Average:         0.500087825501791
A's:     249816
C's:     249805
G's:     250655
T's:     249724 

Seems to work fine each time...

> I'm trying to make some 'control' DNA sequences.
> srand();
> for($x=1;$x<=1000000;$x++)
> {
>         $r = rand(1);
>         if($r <= 0.25){ print "A"; }
>         elsif($r <= 0.5){ print "C"; }
>         elsif($r <= 0.75){ print "G"; }
>         elsif($r <= 1.0){ print "T"; }
> }
> 
> This spews out nonsense sequence but the proportions of bases are not equal.
> A tends to be overrepresented at around 44% or so.  The others are
> correspondingly reduced (sorry, I left the exact figures at home).  I've
> checked that rand(1) really does generate numbers between 0 and 1, so why
> the skew to larger numbers???
> 
> Do I need to tweak srand() somehow?

-- 
Dave Campbell
Geospiza, Inc.
619 N 35th St. Suite 101M
(206) 633-4403
campbell@geospiza.com
=========== Bioperl Project Mailing List Message Footer =======
Project URL: http://bio.perl.org/
For info about how to (un)subscribe, where messages are archived, etc:
http://www.techfak.uni-bielefeld.de/bcd/Perl/Bio/vsns-bcd-perl.html
====================================================================