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

Can I specify bounds for my random number? 3

Status
Not open for further replies.

Jerrycurl

Programmer
Aug 4, 1999
85
US
I need to generate a random number between 1 and 216 with SQL Server 7. Any tips? Thanks.
 
Nevermind, I got it.

select round(1 + (216-1) * rand(),0,0)
 
I was going to propose a similar algorithm I've used since my Basic days, but your's is just as good.

[tt](rand() * MaxNum) + MinNum [/tt] Robert Bradley
teaser.jpg

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top