Script Library

Posted on September 14th, 2006 in Web by Jay

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

RSS feed

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.