DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

shuffle(C++)


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.

(S) 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(C++), Block(C++), drand48(S)
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005