我可以在 Visual Basic 应用程序中手动设置随机化的种子吗
Can I set manually the seed of Randomization in Visual Basic Application
我需要通过设置种子来获得相同的随机序列。
我可以在 Visual Basic 中执行此操作吗?
代码,我用过:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Dim rand As New Random
MsgBox(rand.Next(1, 10))
End Sub
谢谢,祝你有愉快的一天!
所以,吉米带你一路来到酷爱湖..现在你只需要喝一杯!
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Dim rand As New Random(1) 'seed it with 1
MsgBox(rand.Next(1, 10))
End Sub
每次启动此应用程序时,都会在 MsgBox 中看到相同的数字。如果您不喜欢 1,还有超过 40 亿个其他数字可供选择;)
是的,你可以。
来自文档。
You can generate the same sequence of random numbers by providing the
same seed value to the Random(Int32) constructor.
有关示例和详细说明,请参阅下文 link,并搜索“检索相同的随机值序列”。
https://docs.microsoft.com/en-us/dotnet/api/system.random?view=net-5.0
我需要通过设置种子来获得相同的随机序列。 我可以在 Visual Basic 中执行此操作吗?
代码,我用过:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Dim rand As New Random
MsgBox(rand.Next(1, 10))
End Sub
谢谢,祝你有愉快的一天!
所以,吉米带你一路来到酷爱湖..现在你只需要喝一杯!
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Dim rand As New Random(1) 'seed it with 1
MsgBox(rand.Next(1, 10))
End Sub
每次启动此应用程序时,都会在 MsgBox 中看到相同的数字。如果您不喜欢 1,还有超过 40 亿个其他数字可供选择;)
是的,你可以。
来自文档。
You can generate the same sequence of random numbers by providing the same seed value to the Random(Int32) constructor.
有关示例和详细说明,请参阅下文 link,并搜索“检索相同的随机值序列”。
https://docs.microsoft.com/en-us/dotnet/api/system.random?view=net-5.0