"David Alan Black" <dblack / candle.superlink.net> wrote in message
news:g9Sa7.35691$WD1.1946407 / e420r-atl2.usenetserver.com...

> class.  Shuffling is a more method-like concept.  It's also a general
> enough thing that you could make a case for adding it directly to
> class Array.
....
> (Maybe some mathematician could check this for correctness :-)

That is another good reason for adding it to Array. Shuffling is supposedly
not difficult to get right, but it is also surprisingly easy to get wrong.
Having it in a library would avoid many statistical bugs - or get a lot of
them depending on the implementation. (I think I once saw a flawed STL
shuffle, but I didn't check up on it).

One example that can go wrong is shuffling an array of integers from (1..N).
Then pick the first element. Repeat this a number of times. You should get
en even distribution, but in a wrong implementation, you get a different
distribution.

Another useful method is rotate(n). Rotate is modulo length and can be
signed to rotate in the other direction. Note that negative modulo should be
used with care in this case because signed modulo has different
interpretations. Here it means the same as modulo the absolute value, -
"just in the other direction".
The positive direction is from lower index to higher index.

Mikkel