I'm unfamiliar with all the math functions in vb, but I'm good with theory.
I think it should be something like
function RandRange(ByVal Low As Long,ByVal High As Long) As Long
Rand = int((High - Low + 1) * "random number") + Low
end function
somethin like that. look up the random function and replace "random number" with it.
Dragoons Master
Unregistered
Code:
Dim MyValue
MyValue = Int((6 * Rnd) + 1) ' Generate random value between 1 and 6.
Dragoons Master
Unregistered
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.
My fault, I misinterpreted Int().
Dragoons Master
Unregistered
Dragoons Master
Unregistered
GIAKEN Wrote:Dave Wrote:Function Random(Lowerbound As Integer, Upperbound As Integer) as Integer
Dragoons Master Wrote:No return type?
?
Not this one:
Code:
A six second google returned this:
Code: Select all
Function Random(Lowerbound As Long, Upperbound As Long)
Randomize
Random = Int(Rnd * Upperbound) + Lowerbound
End Function
hmmm mk. well im not using MS. but it works and thats good enough for me. at least for now.