Hello all
I have been using the function below to generate x amount of random no. between two no I input (e.g. I need random and unique no between 10 and 50). The function works great, the only problem is that when I use it again to generate a new set of no. it changes the initial ones.
I would like it to generate new no. every time i use it but keep the initial ones (if that makes sens).
'Function RandLotto(Bottom As Integer, Top As Integer, _
Amount As Integer) As String
Dim iArr As Variant
Dim i As Integer
Dim r As Integer
Dim temp As Integer
Application.Volatile
ReDim iArr(Bottom To Top)
For i = Bottom To Top
iArr(i) = i
Next i
For i = Top To Bottom + 1 Step -1
r = Int(Rnd() * (i - Bottom + 1)) + Bottom
temp = iArr(r)
iArr(r) = iArr(i)
iArr(i) = temp
Next i
For i = Bottom To Bottom + Amount - 1
RandLotto = RandLotto & " " & iArr(i)
Next i
RandLotto = Trim(RandLotto)
End Function'
Thanks
Bookmarks