RandomArray

Creates array of random numbers, returns 1 Dim array

Function RandomArray(aLen, Lbound, Ubound)
 Dim I, J, Exists, Nextrand, Newrandom, Result(1)
 Result = Null
 If (aLen >= 1) Then
  Redim Result(aLen - 1)
  Randomize
  For I = 0 To aLen - 1
   Nextrand = True
   Do While Nextrand
    Exists = False
    Newrandom = Int((Ubound - Lbound + 1) * Rnd + Lbound)
    For J = 0 To I - 1
     Exists = Exists Or (Result(J) = Newrandom)
    Next
    If (Not Exists) Then
     Nextrand = False
     Result(I) = Newrandom
    End If
   Loop
  Next
 End If
 RandomArray = Result
End Function

Parameters

aLen, Lbound, Ubound

Views 127 Downloads 56

Perm link


ANmarAmdeen
280
Math Classic ASP
Revisions

v1.0