[thelist] Random value between 1 and x with SQL Server 2K

Guy Babbitt Guy_Babbitt at FSAFOOD.COM
Sun Jul 29 21:18:30 CDT 2001


--guy, set @nvarrs = (ceiling(rand()*(@nvarrc))) looks okay to me

Thanks for the feedback!  I did do a bit of further testing and things look
pretty random (seems weird to say that is a desired result with database lookups
:) ).  I did indeed try it with more records, but found that even with five when
the queries is executed 200 times each record is returned about the same number
of times.  Guess I just jumped the gun and assumed the logic was incorrect.

I appreciate the other feedback.  Just for clarification, the reason I am using
ceiling instead of floor or random is because those functions have the potential
of returning a result of zero, which is not something I can use.  The result
must be between 1 and the total number of rows returned by the query.

Thanks again for all the feedback.

Guy Babbitt
Systems Architect







More information about the thelist mailing list