| Platform: | Visual Basic |
| Task: | Generate real random numbers |
| Discussion: | If you use Dim instead of Static below you will not get random numbers. See http://stackoverflow.com/questions/18676/random-int-in-vb-net |
| Example: | 'http://stackoverflow.com/questions/18676/random-int-in-vb-net
Public Function GetRandomNumber(ByVal Min As Integer, ByVal Max As Integer) As Integer
' by making Generator static, we preserve the same instance '
' (i.e., do not create new instances with the same seed over and over) '
' between calls '
Static Generator As System.Random = New System.Random()
Return Generator.Next(Min, Max)
End Function
|