Script Library
I though I would put together a range of scripts that I use over and over again available for free on the site.
This function will pick random numbers from a range that you specify. I found a few of these functions out on the web however none of them seemed to work correctly, so wrote my own.
Random Numbers
function JRandomNumbers(intFrom,intTo,IntCount)
Dim Nums(), I, J, ArraySize, IsUsed, NextNum
ArraySize = intCount - 1
Redim Nums(ArraySize)
For i = 0 to ArraySize
Randomize
IsUsed = True
Do Until IsUsed = False
NextNum = Int((intTo - intFrom + 1) * Rnd() + intFrom)
IsUsed = BeenUsed(Nums, NextNum)
Loop
Nums(i) = NextNum
Next
JRandomNumbers = Nums
End Function
The above function calls another function called ‘beenused’, which is below:
Function BeenUsed(intNums, intValue)
‘Response.write ”
Checking for the number ” & intValue & “, ”
Dim k, Used
Used = False
for k = 0 to ubound(intNums)
‘Response.write “Pos ” & k & ” = ” & intNums(k) & “, ”
If intNums(k) = intValue Then
Used = True
‘Response.write ” FOUND ”
end if
next
BeenUsed = Used
End Function
No comments yet.