nag_ran_permut_vec (g05ehc) performs a pseudorandom permutation of a vector of integers.
nag_ran_permut_vec (g05ehc) generates a single pseudorandom permutation of the elements of
index without inspecting their values. Each of the
! possible permutations of the
values may be regarded as being equiprobable.
Not applicable.
It should be noted that if
is 20 or more it is theoretically impossible to generate all
! permutations as
! exceeds the cycle length of the internal random number generator. The time taken by the function is of order
. In order to permute other kinds of objects (i.e., vectors, or matrices of higher dimensions), the following technique may be used:
| (a) |
Set , for (where is the number of objects) |
| (b) |
Use nag_ran_permut_vec (g05ehc) to permute index |
| (c) |
Use the contents of index as a set of indices to access the relevant object. |
In order to divide pseudorandomly an array of
objects (obj_array
) into
subgroups of chosen sizes
a similar procedure may be used. For the first
, elements of
index set
, for the next
elements of
index set
, for size
set
, for
, etc. Permute
index using nag_ran_permut_vec (g05ehc) and then, if
, obj_array
is to be included in the
th subgroup.
A vector containing 0 and the first 7 positive integers in ascending order is permuted and the permutation is printed. This is repeated a total of 10 times.
None.