Generate Really Random Value
Seems VB generate predefined values when use functions RND and RANDOMIZE(6.0),
here is minimal improvement which generate You really reandom value...
Rate Generate Really Random Value
(5(5 Vote))
'generate random value between minVal and maxVal inclusive
'or return -1 if any error
Public Function GenerateRandom(minVal As Long, maxVal As Long) As Long
intr = -1
maxVal = maxVal + 1
If maxVal > 0 Then
If minVal >= maxVal Then
minVal = 0
End If
Else
minVal = 0
maxVal = 10
End If
Randomize (DatePart("s", Now) + DatePart("m", Now))
Do While (intr < minVal Or intr = maxVal)
intr = CLng(Rnd() * maxVal)
Loop
GenerateRandom = intr
End Function
Generate Really Random Value Comments
No comments yet — be the first to post one!
Post a Comment