# Thread: Need info to use Random Function

1. ## Re: Need info to use Random Function

You are probably not using the Rnd function correctly. This is from the help file:

In Microsoft Test versions 2.0 and 3.0 following the OPTION INTEGER statement, the RND function generates a random integer between 0 and 65535. In Visual Test, the RND function generates a random number between 0 and 1. To convert a random number between 0 and 1 to the corresponding random integer between 0 and 65535, append * MaxInt to the RND expression.

Hope that helps.

Cheers.

Pete

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

2. ## Re: Need info to use Random Function

Thanks for the tips.
It's not work.

I changed by
RandomNumber = Rnd MaxInt(1,3)
And same error message.

If I want to generate only 1 to 6 number only,what i can do....

3. ## Need info to use Random Function

I can not to generate a random number with function RND

dim RandomNumber as Integer
RandomNumber = Rnd between(1,100)

error VTC4308: '<end of line>' expected before 'between'

I can not find info on the VT Bible & Help to ran this function correctly

Help !

Thanks

BH

4. ## Re: Need info to use Random Function

This is from the Visual Basic 5.0 help file, but it seems to work with Visual Test...
******************************
To produce random integers in a given range, use this formula:

Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

Here, upperbound is the highest number in the range, and lowerbound is the lowest number in the range.

Note: To repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument. Using Randomize with the same value for number does not repeat the previous sequence.
******************************

Here's some code that generates random numbers from 1 to 6. I've included the RANDOMIZE function but it doesn't seem to work. When uncommented, it only generates the number "1". So, if you can get it to work, please send it along.

Hope this helps,
Keith

FYI - This was coded with VT version 4.0

Scenario "Random Number"

Dim i as Integer
Dim iRandomNum as Integer
Dim iUpperBound as Integer
Dim iLowerBound as Integer

iUpperBound = 6
iLowerBound = 1

Viewport Clear

For i = 1 to 10

'RANDOMIZE(Int(Val(Time)))
RANDOMIZE(i)
' Formula for generating a randon integer from n to n
' Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
' Generate random value between 1 and 6.
iRandomNum = Int(((iUpperBound - iLowerBound + 1) * Rnd) + iLowerBound)
' Print the number to the Viewport...
Print iRandomNum

Next i

End Scenario

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

[This message has been edited by jkmcleod (edited 04-21-2001).]

[This message has been edited by jkmcleod (edited 04-21-2001).]

5. ## Re: Need info to use Random Function

In order to randomize, you need to use TIMER:

Scenario "Random Number"

Dim i as Long
Dim iRandomNum as Long
Dim iUpperBound as Long
Dim iLowerBound as Long

iUpperBound = (TIMER * 10)
iLowerBound = 1

Viewport Clear

RANDOMIZE(iUpperBound)
For i = 1 to 20
'RANDOMIZE(i)
' Formula for generating a randon integer from n to n
' Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
' Generate random value between 1 and 6.
iRandomNum = Int(((iUpperBound - iLowerBound + 1) * Rnd) + iLowerBound)
' Print the number to the Viewport...
Print iRandomNum

Next i

End Scenario

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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 11:11 AM.