Random numbers on a computer are actually pseudo-random number. Given the same random seed, the paterern of random values returned between executions will remain the same. The solution to this is to set the random number generator with a new seed value everytime you run the script. This code will help to give a a better patern of random numbers.
Include this code in your vuser_init:
vuser_init()
{
/*** Seed the random number generator once per script with the current time ***/
/*** If this is not done, the same numbers may be generated ***/
srand ( time(NULL) );
return 0;
}
Then add this subroutine to your script in globals.h:
/*** Function - GetRandomNumber ***/
int GetRandomNum (int MaxNum)
{
int RandNum = 0;
/*** Use the rand function to get a Random number from 0 to MaxNum ***/
RandNum = (int)((rand()%MaxNum)+1);
return RandNum;
}
Then call the subroutine from your action section whenever you need a random number
actions()
{
int RandomNumber, i; //Receives the value from the random routine
int MaxNum =32000; //Set the upper limit of the random numbers
/*** Get ten random values from 0 to 200 ***/
for( i = 1; i < 10; i++)
{
RandomNumber = GetRandomNum(MaxNum); //This is the call to the function
lr_output_message(''Random Number = %d'', RandomNumber); //Display a message
}
return 0;
}