To generate a random value between a lowerBound and an upperBound, use the standard scaling formula: random() * (upperBound - lowerBound) + lowerBound for decimal numbers, or floor(random() * (upperBound - lowerBound + 1)) + lowerBound for inclusive integers. Most programming languages and spreadsheet tools also provide built-in functions to do this directly.
VB.NET
' Initialize the random-number generator. Randomize() ' Generate random value between 1 and 6. Dim value As Integer = CInt(Int((6 * Rnd()) + 1))
The Rnd function returns a value less than 1, but greater than or equal to zero. Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.
References:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.vbmath.rnd?view=net-10.0
0 Comments:
Post a Comment