Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Function?
#6
seraphelic Wrote:
Dragoons Master Wrote:
Code:
Dim MyValue
MyValue = Int((6 * Rnd) + 1)   ' Generate random value between 1 and 6.

That wouldn't work. if Rnd turned out to be .9, then MyValue would equal 7.

Here's a working function.
Function Rand(ByVal Low As Long, ByVal High As Long) As Long
Rand = Int((High - Low + 1) * Rnd) + Low
End Function
Actualy... no, Int(6*0,9)+1 = 6
I got that example from MSDN, so it actually can't be wrong...
But for any range:
Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Also got it from MSDN.
I miss read the first example.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)