Thanks:  0
Likes:  0
Dislikes:  0

1. ## Generate Random Number

User (JosephH614@aol.com) posted:

--part1_9f.17278c5b.286415f8_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

I am trying to generate a random number (between two boundaries) that will be
used in a function later in my script, but my code does not seem to be
working:

int n;

{
n=rand(5,100);
return(n);
}

Can someone give me some advice?

Many thanks!
Joseph

--part1_9f.17278c5b.286415f8_boundary
Content-Type: text/html; charset=US-ASCII
Content-Transfer-Encoding: 7bit

< !-- |**|begin egp html banner|**| -->

2. ## Re: Generate Random Number

User Andrew McFarlane (welkin_inc@hotmail.com) posted:

Try:

int myRand( int lower, int upper ) {

return( ( rand() % ( upper + 1 - lower ) ) + lower );
}

rand() % N will produce a number between 0 and N-1.

As an example, if lower = 5 and upper = 100,

( rand() % ( 100 + 1 - 5 ) ) + 5 = ( rand() % 96 ) + 5

rand() % 96 produces a number between 0 and 95, so by adding 5 it produces a
number between 5 and 100.

Andrew
----Original Message Follows----
From: JosephH614@aol.com
Date: Thu, 21 Jun 2001 23:31:04 EDT

I am trying to generate a random number (between two boundaries) that will
be
used in a function later in my script, but my code does not seem to be
working:

int n;

{
n=rand(5,100);
return(n);
}

Can someone give me some advice?

Many thanks!
Joseph

__________________________________________________ _______________

3. ## Re: Generate Random Number

User Neil Cameron (neil.cameron@telelogic.com) posted:

------_=_NextPart_001_01C0FAF6.25D48F40
Content-Type: text/plain;
charset="iso-8859-1"

try this

int GetRandom(int min, int max)
{
// Generate a random number between min and max
int rndnum;

do
{
rndnum = ((rand()) % (max + 1));
}
while (rndnum > max &#0124; &#0124; rndnum < min);

return rndnum;
}

and put this line somewhere that it is only going to be executed once per
vuser
// Initialise random number seed
srand(clock());

4. ## Re: Generate Random Number

User (firmanf@yahoo.com) posted:

Actually,
it is probably better to use the 'random number' parameter in
LoadRunner. What I've observed is that rand() depends on a seed,
and most of the what you'll see is that all of the vusers started
with the same seed, and you'll end up with a lot less randomness
than you'd expect. On the other hand, the random number parameter
seems to be shared across several vuser threads, and as such has
a lot more randomness than the rand() function.

Ferry

--- In LoadRunner@y..., Neil Cameron <neil.cameron@t...> wrote:
once per
that will
be
oupmai

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

5. ## Re: Generate Random Number

___________________________
User (JosephH614@aol.com) posted:

I am trying to generate a random number (between two boundaries) that will be
used in a function later in my script, but my code does not seem to be
working:

int n;

{
n=rand(5,100);
return(n);
}

Can someone give me some advice?

Many thanks!
Joseph
___________________________

Joseph,

Why don't you use the built in random type
parameter?!

int iMyRandNumber;

iMyRandNumber = atoi (lr_eval_string("{rnd}"));

where {rnd } is a parameter of random type.

Regards,
--Ilia

------------------

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.