HyPhy message board
http://www.hyphy.org/cgi-bin/hyphy_forums/YaBB.pl
HYPHY Package >> HyPhy feedback >> Random Seed issue?
http://www.hyphy.org/cgi-bin/hyphy_forums/YaBB.pl?num=1328206388

Message started by SamW on Feb 2nd, 2012 at 10:13am

Title: Random Seed issue?
Post by SamW on 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");
}

Title: Re: Random Seed issue?
Post by Sergei on 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);
[/code]

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

Sergei

HyPhy message board » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2024. All Rights Reserved.