% Dim intLowerBound ' Lower bound of the random number range Dim intUpperBound ' Upper bound of the random number range Dim intRangeSize ' Size of the range Dim sngRandomValue ' A random value from 0 to intRangeSize Dim intRandomInteger ' Our final result - random integer to return ' Retrieve lower and upper bound requests if they're there ' o/w set to defaults of 0 and 100 intLowerBound = 1 intUpperBound = 105 Randomize() ' Generate our random number. ' The Rnd function does most of the work. It returns a value in the ' range 0 <= value < 1 so to generate a random integer in the specified ' range we need to do some calculation. Specifically we take the size ' of the range in which we want to generate the number (add 1 so the ' upper bound can be generated!) and then multiply it by our random ' element. Then to place the value into the correct range of numbers ' we add the lower bound. Finally we truncate the number leaving us ' with the integer portion which is always somewhere between the ' lower bound and upper bound (inclusively). ' Find range size intRangeSize = intUpperBound - intLowerBound + 1 ' Get a random number from 0 to the size of the range sngRandomValue = intRangeSize * Rnd() ' Center the range of possible random numbers over the desired result set sngRandomValue = sngRandomValue + intLowerBound ' Convert our value to an integer intRandomInteger = Int(sngRandomValue) ' The above 4 lines are equivilent to the popular shorter version ' below. I split it up so I could indicate what each step is doing. ' intRandomInteger = Int((intUpperBound - intLowerBound + 1) * Rnd + intLowerBound) ' Show out output indicating what we've done and our result. dim adoConn,rsInv,sSQL application("ConnString") = "Provider=SQLOLEDB;Data Source=10.100.0.23;"&_ "Initial Catalog=MusicalMotivator;User Id=MusicalMotivatorWeb;Password=odbc!u$er;" set adoConn = Server.CreateObject("ADODB.Connection") adoConn.Open Application("ConnString") set rsInv = Server.CreateObject("ADODB.Recordset") sSQL = "SELECT Quote from Quotes where QuoteID = "& intRandomInteger &"" rsInv.Open sSQL, adoConn %>