LoadNoDupleRnd




Static Function Shuffle(Lower As Integer, _
Upper As Integer) As Integer
Static PrimeFactor(10) As Integer
Static a As Integer, b As Integer, c As Integer
Static s As Integer, n As Integer
Dim i As Integer, j As Integer, k As Integer
Dim m As Integer
Dim t As Boolean
If (n <> Upper - Lower + 1) Then
n = Upper - Lower + 1
i = 0
m = n
k = 2
Do While k <= m
If (m Mod k = 0) Then
If (i = 0 Or PrimeFactor(i) <> k) Then
i = i + 1
PrimeFactor(i) = k
End If
m = m / k
Else
k = k + 1
End If
Loop
b = 1
For j = 1 To i
b = b * PrimeFactor(j)
Next j
If n Mod 4 = 0 Then b = b * 2
a = b + 1
c = Int(n * .66)
t = True
Do While t
t = False
For j = 1 To i
If ((c Mod PrimeFactor(j) = 0) Or _
(c Mod a = 0)) Then t = True
Next j
If t Then c = c - 1
Loop
Randomize
s = Rnd(n)
End If
s = (a * s + c) Mod n
Shuffle = s + Lower
End Function

'Here's how to fill an array with 20 non-duplicating random

'numbers between 1 and 100:

For i = 1 To 20
num(i) = Shuffle(1,100)
Next i
The following code will fill an array with a specified amount
of random numbers without duplication:










( loadnoduplernd.html )- by Paolo Puglisi - Modifica del 17/12/2023