  We give an algorithm which produces a unique element of the Clifford group
$\mathcal{C}_n$ on $n$ qubits from an integer $0\le i < |\mathcal{C}_n|$ (the
number of elements in the group). The algorithm involves $O(n^3)$ operations.
It is a variant of the subgroup algorithm by Diaconis and Shahshahani which is
commonly applied to compact Lie groups. We provide an adaption for the
symplectic group $Sp(2n,\mathbb{F}_2)$ which provides, in addition to a
canonical mapping from the integers to group elements $g$, a factorization of
$g$ into a sequence of at most $4n$ symplectic transvections. The algorithm can
be used to efficiently select random elements of $\mathcal{C}_n$ which is often
useful in quantum information theory and quantum computation. We also give an
algorithm for the inverse map, indexing a group element in time $O(n^3)$.
