ASP - 随机化功能为两个不同的种子
问题描述:
所以我产生使用赛第一轮和随机化设置种子,看起来像这样一个随机数返回相同的值:ASP - 随机化功能为两个不同的种子
Randomize lSeed
Response.Write Rnd
我注意到,它的返回对于lSeed(例如123,124),在一行中的两个值的结果相同但是在125上它将返回一个新值,但是126将与125中的on相同。为什么会这样呢?
编辑:
我已经试过这样的事情
Randomize
Randomize lSeed
Response.write Rnd
而且我得到我上述相同的结果。
答
的问题是,该值因为种子在其他环境中太大(数据库值增加)。我最终做了Mod 100的价值,以获得半随机的东西,而且总是会工作的很低。
答
' 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
您能否为此展示更完整的代表,我没有得到您的结果,我得到的行为与您所描述的不同。一个随机的固定种子获得一个独特的系列。 – AnthonyWJones 2008-11-12 15:43:38