Page 1 of 1

Issue in Random number generation()

Posted: June 30th, 2015, 9:29 am
by rameshpal
hi friends ,

we are trying to generate a random number between 1, 2 and 3. the issue we are facing is that every time we open the CSPro file again, it generates the number 2 every time. Though when we add cases in the same file, then it generates random number. I have tried using both random(1,3) and randomin(1,2,3) but am still facing the same issue.

Would appreciate if some one can help me on this issue.
Thanks in Advance!!

Re: Issue in Random number generation()

Posted: June 30th, 2015, 12:02 pm
by josh
To generate different sequences of random numbers each time you run you need to seed the random number generator with a value that will be different each time the application is run. I would recommend using the system time as a seed value. Seed the random number generator once at the start of the program such as in the preproc of the FF. Something like this:

PROC SURVEY_FF
preproc
// Seed random number generator with current time
seed(systime());