Static Function Shuffle(Lower As Integer, Upper As Integer) As Integer
Static PrimeFactor(10) As Integer Static a As Integer, c As Integer, B As Integer Static s As Long, n As Integer Dim i As Integer, J As Integer, k As Integer Dim m As Integer If (n <> Upper - Lower + 1) Then n = Upper - Lower + 1 i = 0 n1 = n k = 2 Do While k <= n1 If (n1 Mod k = 0) Then If (i = 0 Or PrimeFactor(i) <> k) Then i = i + 1 PrimeFactor(i) = k End If n1 = n1 / 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 * 0.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 Functi |