ASP - Randomize function returns the same value for two different seeds
So, I am generating a random number using Rnd and Randomize to set a seed that looks like this:
Randomize lSeed
Response.Write Rnd
I notice that it returns the same result for two values ββin a row for lSeed (e.g. 123, 124), but then say 125, it will return a new value, but 126 will be the same as for 125. Why should this be ?
Edit:
I've tried something like this
Randomize
Randomize lSeed
Response.write Rnd
And I get the same results as I described above.
0
source to share
5 answers
' For ASP, you can create a function like:
Public Function RandRange(ByVal low As Integer, ByVal high As Integer) As Integer
Randomize()
Return ((Rnd() * (high - low)) + low)
End Function
' For ASP.NET, you can create a function like:
Private _rnd As System.Random()
Public Function RandRange(ByVal low As Integer, ByVal high As Integer) As Integer
' Purpose: Returns Random Integer between low and high, inclusive
' Note: _rnd variable must be defined outside of RandRange function
If _rnd Is Nothing Then
_rnd = New System.Random()
End If
Return _rnd.Next(low, high)
End Function
0
source to share