This will be a better random number generator than the other options you mentioned, yes.
The code is nicely indented, but some whitespace between variable declarations and logic would be nice.
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 SubMethod names should be
PascalCased, soRandomgeneratorshould beRandomGenerator. Don't use underscore in variable/parameter names. They should becamelCased. Please see the official MSDN capitalization recommendations for more information.This is begging to be a function that returns a
longInteger. There should be a main routine that calls and displays the generated number.Public Function RandomGenerator() As LongInteger Dim byteCount As Byte() = New Byte(6) {} Dim randomNumber As New RNGCryptoServiceProvider() randomNumber.GetBytes(byteCount) Return BitConverter.ToInt32(byteCount, 0) End Function Sub Main() MsgBox(RandomGenerator()) End SubMsgBoxis depreciated and left only for backwards compatibility with vb6. Replace it with a MessageBox.RNGCryptoServiceProviderimplementsIDisposable. This means that you need to properly disposerandomNumber. From the documentation link you provided:
This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the “Using an Object that Implements IDisposable” section in the IDisposable interface topic.