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

Anthony Baratta Anthony at Baratta.com
Sun Jul 29 13:36:22 CDT 2001


At 11:05 AM 7/29/2001, you wrote:

>There must be a way to pull this off within transact-sql, the code I included
>before gave me back a random value, but does not appear to be truly random 
>from
>the testing I have done (ie with 5 possible records 3 and 4 come up a lot more
>often than 1, 2, or 5).

The trasact-sql Random function accepts a seed. Calculate the seed with the 
calling program language and pass that to the stored proceedure:

e.g ASP VB SCript example...

'' Collecting Random Numbers
     varRandomSeed = Right(ABS(DateDiff("s",Now,#1/1/1998#)),4)

Const DB_Conn_String = "Data Source=Blah;UID=Blah;Pwd=blah;"

Set objDB_Conn = Server.CreateObject("ADODB.Connection")
     objDB_Conn.Open DB_Conn_String

Set objRS = objDB_Conn.Open("EXEC Stored_Procedure " & varRandomSeed )

Or some facsimile therefore.
---
Anthony Baratta
President
Keyboard Jockeys

Blatant Plug: Cool Jazz for a hot summer,
     http://LisaMarie.Baratta.com





More information about the thelist mailing list