shuffle(3C++)


shuffle -- shuffle an array in place

Synopsis

   template <class T>
   void shuffle(T* b,T* e);
   template <class T>
   void shuffle_c(const T* b1,const T* e1,T* b2);

Assumptions

(1) For the copy version, the output array and the input array do not overlap.

(2) For the copy version, the output array has at least as many cells as the input array.

(3) T has operator=.

Description

These functions shuffle (i.e., randomly permute) an array in place.

   template <class T>
   void shuffle(T* b,T* e);

Performs an in-place shuffle.

   template <class T>
   void shuffle_c(const T* b1,const T* e1,T* b2);

Like shuffle except that the input array is preserved and the result written to a new array beginning at location b2.

Complexity

If N is the size of the array, then complexity is O(N). Exactly 3(N-1) assignments are done.

Notes

These functions use drand48(3C) to obtain pseudo-random numbers.

Because a Block (see Block(3C++)) can always be used wherever an array is called for, Array Algorithms can also be used with Blocks. In fact, these two components were actually designed to be used together.

References

Array_alg(3C++), Block(3C++), drand48(3C)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004