Skip to main content
added 6 characters in body
Source Link
RubberDuck
  • 31.2k
  • 6
  • 74
  • 177
  • 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 Sub
    
  • Method names should be PascalCased, so Randomgenerator should be RandomGenerator. Don't use underscore in variable/parameter names. They should be camelCased. 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 Sub
    
  • MsgBox is depreciated and left only for backwards compatibility with . Replace it with a MessageBox.

  • RNGCryptoServiceProvider implements IDisposable. This means that you need to properly dispose randomNumber. 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.

  • 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 Sub
    
  • Method names should be PascalCased, so Randomgenerator should be RandomGenerator. Don't use underscore in variable/parameter names. They should be camelCased. Please see the official MSDN capitalization recommendations for more information.

  • This is begging to be a function that returns a long. There should be a main routine that calls and displays the generated number.

     Public Function RandomGenerator() As Long
         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 Sub
    
  • MsgBox is depreciated and left only for backwards compatibility with . Replace it with a MessageBox.

  • RNGCryptoServiceProvider implements IDisposable. This means that you need to properly dispose randomNumber. 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.

  • 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 Sub
    
  • Method names should be PascalCased, so Randomgenerator should be RandomGenerator. Don't use underscore in variable/parameter names. They should be camelCased. Please see the official MSDN capitalization recommendations for more information.

  • This is begging to be a function that returns a Integer. There should be a main routine that calls and displays the generated number.

     Public Function RandomGenerator() As Integer
         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 Sub
    
  • MsgBox is depreciated and left only for backwards compatibility with . Replace it with a MessageBox.

  • RNGCryptoServiceProvider implements IDisposable. This means that you need to properly dispose randomNumber. 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.

added 616 characters in body
Source Link
RubberDuck
  • 31.2k
  • 6
  • 74
  • 177
  • 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 Sub
    
  • Method names should be PascalCased, so Randomgenerator should be RandomGenerator. Don't use underscore in variable/parameter names. They should be camelCased. Please see the official MSDN capitalization recommendations for more information.

  • This is begging to be a function that returns a long. There should be a main routine that calls and displays the generated number.

     Public Function RandomGenerator() As Long
         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 Sub
    
  • MsgBox is depreciated and left only for backwards compatibility with . Replace it with a MessageBox.

  • RNGCryptoServiceProvider implements IDisposable. This means that you need to properly dispose randomNumber. 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.

  • 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 Sub
    
  • Method names should be PascalCased, so Randomgenerator should be RandomGenerator. Don't use underscore in variable/parameter names. They should be camelCased. Please see the official MSDN capitalization recommendations for more information.

  • This is begging to be a function that returns a long. There should be a main routine that calls and displays the generated number.

     Public Function RandomGenerator() As Long
         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 Sub
    
  • MsgBox is depreciated and left only for backwards compatibility with . Replace it with a MessageBox.

  • 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 Sub
    
  • Method names should be PascalCased, so Randomgenerator should be RandomGenerator. Don't use underscore in variable/parameter names. They should be camelCased. Please see the official MSDN capitalization recommendations for more information.

  • This is begging to be a function that returns a long. There should be a main routine that calls and displays the generated number.

     Public Function RandomGenerator() As Long
         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 Sub
    
  • MsgBox is depreciated and left only for backwards compatibility with . Replace it with a MessageBox.

  • RNGCryptoServiceProvider implements IDisposable. This means that you need to properly dispose randomNumber. 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.

Source Link
RubberDuck
  • 31.2k
  • 6
  • 74
  • 177

  • 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 Sub
    
  • Method names should be PascalCased, so Randomgenerator should be RandomGenerator. Don't use underscore in variable/parameter names. They should be camelCased. Please see the official MSDN capitalization recommendations for more information.

  • This is begging to be a function that returns a long. There should be a main routine that calls and displays the generated number.

     Public Function RandomGenerator() As Long
         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 Sub
    
  • MsgBox is depreciated and left only for backwards compatibility with . Replace it with a MessageBox.