我附带了以下编码来生成 1000-9999 内的范围:
Dim byt As Byte() = New Byte(1000) {}
Dim rngCrypto As New RNGCryptoServiceProvider()
rngCrypto.GetBytes(byt)
Dim randomNumber As Integer = BitConverter.ToInt32(byt, 9999)
Label4.Text = randomNumber
它显示错误:
指数超出范围。必须是非负数且小于集合的大小。参数名称:
startIndex
我已经完成了以下代码。这是正确的吗?
公共子secrand()
Static r As Random = Nothing
If r Is Nothing Then
Dim seed() As Byte = New Byte(4) {}
Dim rng As New RNGCryptoServiceProvider
rng.GetBytes(seed)
r = New Random(BitConverter.ToInt32(seed, 0))
Label4.Text = r.Next(1000, 9999)
End If
End Sub