Function RandInt(ByVal loVal As Int32, ByVal hiVal As Int32) As Int32
Static r As Random = Nothing
If r Is Nothing Then
Dim seed() As Byte = New Byte(3) {}
Dim rng As New RNGCryptoServiceProvider
rng.GetBytes(seed)
r = New Random(BitConverter.ToInt32(seed, 0))
End If
Return r.Next(loVal, hiVal + 1)
End Function
--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Mark Jones" <no**************@devnullbucket.org> wrote in message
news:41**********************@news.twtelecom.net.. .
I need a little hlep.
Can anyone show me how to use RNGCryptoServiceProvider
to return an integer value within a specified range using vb.net?
The function would look something like this
Private Function RandInt(loVal as Integer, hiVal as integer) as Integer
'[INSERT CODE TO USE RNGCryptoServiceProvider Here]
End Function
I know I need to import System.Security.Cryptography
I know I need to use a 4 byte array as a buffer.
I just can't quite get it to work with the convert object.
TIA
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.805 / Virus Database: 547 - Release Date: 03/12/2004