Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

statements that assing random integers to variable n 1

Status
Not open for further replies.

tjorda23

Technical User
May 25, 2002
2
US
I am trying to write statements that assign random integers to the variable n in the following ranges;
a) 1 greater than or equal to n greater than or equal to 2 (did not know how to make the greater than or equal to symbol appear here so I wrote it out.
b) 1 greater than or equal to n greater than or equal to 100

c) 0 greather than or equal to n greater than or equal to 9

d) 1000 greater than or equal to n greater than or equal to 1112

e) -1 greater than or equal to n greater than or equal to 1

f) -3 greater than or equal to n greater than or equal to 11.

Does any one have helpful hints, tips etc.

Thanx!!

 
Look into the random number function. You can set the interval, lower and upper bounds and it will return a number within the range you specify. It is used a lot in games such as rolling dice, etc. Thanks and Good Luck!

zemp
 
To expand on what zemp wrote,

Use randomize to reseed to random number generator (or you may get the same 'random' numbers each time!

Use rnd to generate a random number.

The rnd function returns a real number between 0 and 1. Multiply this by the required range e.g. clng(rnd*10) will give a number between 0 and 10. You can then add an offset e.g. clng(rnd*5)+5 will give a number between 5 and 10.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top