ASP - 随机化功能为两个不同的种子

问题描述:

所以我产生使用赛第一轮和随机化设置种子,看起来像这样一个随机数返回相同的值:ASP - 随机化功能为两个不同的种子

Randomize lSeed 
Response.Write Rnd 

我注意到,它的返回对于lSeed(例如123,124),在一行中的两个值的结果相同但是在125上它将返回一个新值,但是126将与125中的on相同。为什么会这样呢?

编辑:

我已经试过这样的事情

Randomize 
Randomize lSeed 
Response.write Rnd 

而且我得到我上述相同的结果。

+0

您能否为此展示更完整的代表,我没有得到您的结果,我得到的行为与您所描述的不同。一个随机的固定种子获得一个独特的系列。 – AnthonyWJones 2008-11-12 15:43:38

的问题是,该值因为种子在其他环境中太大(数据库值增加)。我最终做了Mod 100的价值,以获得半随机的东西,而且总是会工作的很低。

您应该在每次获得随机值之前进行种子培植。我建议播种定时器。

+0

我试过重新种植。我编辑了上面的问题来解释我所尝试过的。 – Jon 2008-11-11 20:30:13

你也可以关闭种子的,似乎工作得很好当前时间

+0

我需要有时返回一致的结果,所以我需要重新从我给它的值。 – Jon 2008-11-11 20:30:45

+1

如果你想要一致的结果,你可能不应该使用随机数字。 – Karl 2008-11-11 20:34:02

' 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