Program RANDTOUR.BAS selects permutations at random only in its ``simplest" variant. Here are a few examples of problems that require selecting random permutations.
Suppose there are 7 items hidden under 12 cups, and a person is allowed to try to find them. How often all seven will be recovered by pure lack (as opposed to, say, parapsychic abilities?
The ``naive" selection of random permutation wastes many random numbers. Here is
an algorithm that conserves resources better. The basic idea is to select
a number from the beginning of the list of all numbers, and move it down to the end. The randomly re-arranged numbers are
SUB GetPermutationFast(P())
'Put random integers into P()
n=UBOUND(P) 'how many entries
'this loop can be omitted is we are sure that P(j) list all the numbers we want
FOR j=1 TO n
P(j)=j
next j
for j=1 to UBOUND(P) 'not n as n changes in the loop
k=INT(RND(1)*n+1)
SWAP P(n), P(k)
n=n-1
next j