While surfing and through some experimentation, I have a new method to generate random numbers without using Randomize
or Random
or RND
. It uses RNGCryptoServiceProvider Class for generating random numbers. We can generate a wide range of positive and negative random numbers with this. I built a function which generate positive and negative random numbers.I wish to share that code with you to make it much better.
We need to import Imports System.Security.Cryptography
file to work with the function. Here is the code:
Public Sub Randomgenerator()
Dim byte_count As Byte() = New Byte(6) {}
Dim random_number As New RNGCryptoServiceProvider()
random_number.GetBytes(byte_count)
Dim Output As Integer = BitConverter.ToInt32(byte_count, 0)
MsgBox(Output)
End Sub
Suggestions and tips to improve this function are invited.