Create random float numbers using a range

Hi,

How can you create random float numbers using a range in tsql?

Thank you

DECLARE @Upper float;
DECLARE @Lower float 
SET @Lower = 1.2 -- The lowest random number
SET @Upper = 7.6 -- The highest random number
SELECT Round(((@Upper - @Lower -1) * Rand() + @Lower), 0)

Open in new window

crompnkData Management SpecialistAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Here you go.  Also I have an article you can look at that uses a lot of Rand() functions.

Declare @min float, @max float, @rand float

SELECT @min = 1.2, @max = 7.6
SELECT @rand = ((@max + 1) - @min) * Rand() + @min 

SELECT @rand

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.