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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

specify minimum value for random 1

Status
Not open for further replies.

crystalhelp

Programmer
May 13, 2002
56
CA
I found the following in the forum archives.

select (rand() * MaxNum) + MinNum

However, it doesn't work. I specified 59 as my max and 48 as my min. It returned random numbers higher than 59. If I set my MinNum to 1, it returned numbers from 1-59. How can I specify a range from 48-59?
 
Try

select (rand() * MaxNum-MinNum) + MinNum

For the range 48-59 that works out to

select (rand() * 11) + 48
 
I missed a necessary set of parenthesis in the above formula. It should be

select (rand() * (MaxNum-MinNum)) + MinNum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top