Thanks:  0
Likes:  0
Dislikes:  0

1. ## Random number generators

To generate a random number, I would use:

mynum = (6 * Rnd) + 1

From the code, i can see that the number generated will be a float with several numbers after decimal. Is there a way to generate a random number with 3 decimals, for example?

Thanks.

2. ## Re: Random number generators

mynum = int(6000 * Rnd + 1) / 1000

3. ## Re: Random number generators

I figures that one. Also i thought of generating 2 numbers then putting them together. but is there a decimal limiter on the RNd function?

4. ## Re: Random number generators

I use this (stolen from QTP help!);

number = Int((upperbound - lowerbound +1) * RND + Lowerbound)

It always returns a whole number

5. ## Re: Random number generators

[ QUOTE ]
I figures that one. Also i thought of generating 2 numbers then putting them together. but is there a decimal limiter on the RNd function?

[/ QUOTE ]

I doubt it.

Rnd() is a fairly pure concept. Generate a pseudo-random number between 0 and 1. Once you get that number, it's up to you to decide what you want to do with it - multipliers, limits, truncations, whatever you want.

I suppose you could always create your own function. A wrapper for the Rnd() function. Register it and call it as you like.

Or just handle it in your script.

6. ## Re: Random number generators

Try this:
number = Round(((5- 1 +1) * RND + 1) , 3)

where number = 4.528

7. ## Re: Random number generators

[ QUOTE ]
Try this:
number = Round(((5- 1 +1) * RND + 1) , 3)

where number = 4.528

[/ QUOTE ]Thats it!

8. ## Re: Random number generators

Or use QTP's inbuilt random number generator, this is from the help:

The following example generates a random number between 0 and 100.

x=RandomNumber (0,100)

Mark Smith.

9. ## Re: Random number generators

[ QUOTE ]
Or use QTP's inbuilt random number generator, this is from the help:

The following example generates a random number between 0 and 100.

x=RandomNumber (0,100)

Mark Smith.

[/ QUOTE ]wouldnt that return a whole number?

10. ## Re: Random number generators

Sorry mSky, yes it would.

I must learn to read all of the post, not just the 1st 2 lines.

Mark Smith.

#### 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.40 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.