' version 22-10-2016 ' compile with: fbc -s console ' for boundry checks on array's compile with: fbc -s console -exx ' sort from lower bound to the highter bound ' array's can have subscript range from -2147483648 to +2147483647 Sub knuth_down(a() As Long) Dim As Long lb = LBound(a) Dim As ULong n = UBound(a) - lb +1 Dim As ULong i, j Randomize Timer For i = n -1 To 1 Step -1 j =Fix(Rnd * (i +1)) ' 0 <= j <= i Swap a(lb + i), a(lb + j) Next End Sub Sub knuth_up(a() As Long) Dim As Long lb = LBound(a) Dim As ULong n = UBound(a) - lb +1 Dim As ULong i, j Randomize Timer For i = 0 To n -2 j = Fix(Rnd * (n - i) + i) ' 0 <= j < n-i, + i ==> i <= j < n Swap a(lb + i), a(lb + j) Next End Sub ' ------=< MAIN >=------ Dim As Long i Dim As Long array(1 To 52), array2(-7 To 7) For i = 1 To 52 : array(i) = i : Next Print "Starting array" For i = 1 To 52 Print Using " ###";array(i); Next : Print : Print knuth_down(array()) Print "After Knuth shuffle downwards" For i = 1 To 52 Print Using " ###";array(i); Next : Print : Print For i = LBound(array2) To UBound(array2) array2(i) = i - LBound(array2) + 1 Next Print "Starting array, first index <> 0 " For i = LBound(array2) To UBound(array2) Print Using " ##";array2(i); Next : Print : Print knuth_up(array2()) Print "After Knuth shuffle upwards" For i = LBound(array2) To UBound(array2) Print Using " ##";array2(i); Next : Print : Print ' empty keyboard buffer While InKey <> "" : Wend Print : Print "hit any key to end program" Sleep End