Welcome, Guest. Please Login
YaBB - Yet another Bulletin Board
 
  HomeHelpSearchLogin  
 
Random Seed issue? (Read 1667 times)
SamW
YaBB Newbies
*
Offline


Feed your monkey!

Posts: 18
Random Seed issue?
Feb 2nd, 2012 at 10:13am
 
Hello Sergei,

If I create a random number in a HyPhy script and then loop it using a bash submission to HYPHYMP, it appears that the seed does not change (i.e. I get the same random number every time.  However, if I loop within HyPhy, I get a different random number each time.

For example, I bashed nullrandomtest.h (cut and pasted below msg) using the nullrandomtest.sh bash file (cut and pasted below msg) and I got back 10 identical values.  However, when I HYPHYMP the file nullrandomtest_loop.h (cut and pasted below this msg) I get 10 different random numbers.

Am I missing something or is there a way around this?

Respectfully,
Sam

nullrandomtest.sh:
#!/bin/bash
bigcount="0"
while [ $bigcount -lt 10 ]
do
HYPHYMP ./nullrandomtest.h
let bigcount=$bigcount+1
done

nullrandomtest.h:
test = Random(0,1);
fprintf(stdout,test,"\n");

nullrandomtest_loop.h:
for(i=0;i<10;i=i+1)
{
     test = Random(0,1);
     fprintf(stdout,test,"\n");
}
Back to top
 
 
IP Logged
 
Sergei
YaBB Administrator
*****
Offline


Datamonkeys are forever...

Posts: 1658
UCSD
Gender: male
Re: Random Seed issue?
Reply #1 - Feb 3rd, 2012 at 1:37pm
 
Hi Sam,

HyPhy initializes the random number generator with the current system time (in seconds since the beginning of the current epoch) when it is launched. It sounds like your bash loop is launching instances of HyPhy in the same second, hence they all get the same starting seed and generate the same sequence of numbers. You can use

Code:
SetParameter (RANDOM_SEED, value);
 



to initialize the random number generator to whichever value you like (e.g. something piped in from /dev/random)

Sergei
Back to top
 

Associate Professor
Division of Infectious Diseases
Division of Biomedical Informatics
School of Medicine
University of California San Diego
WWW WWW  
IP Logged