Re: Adding functions to generic package



Preben Randhol <randhol+valid_for_reply_from_news@xxxxxxx> writes:

> > Get_Random_Iterator returns an iterator (J) in the range [I, Back):
>
> Not sure I understand this. Wouldn't this mean that the randomisation
> only will be able to put element further back in the list?

No, since J is moved (spliced) from the range [I, Back) to position I
(elements are thus moved from the back to the front).

There are two ranges: [front, I), which stores the randomized elements,
and [I, back), which stores the non-randomized elements.

The list starts out completely non-randomized, so [front, I) is empty
and [I, back) represents the entire list.

During iteration, Get_Random_Iterator is used to randomly select an
element from [I, back), then it gets moved (spliced) at the end of the
randomized range (just before I). This means that every pass through
the loop, the range [front, I) grows and [I, back) shrinks.

The iteration terminates when [I, back) has only a single element.
.