From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7e81a70d49e1dad0 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!elnk-atl-nf1!newsfeed.earthlink.net!stamper.news.atl.earthlink.net!newsread1.news.atl.earthlink.net.POSTED!14bb18d8!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada Subject: Re: Adding functions to generic package References: <429891d3$1@news.broadpark.no> <4298b608$1@news.broadpark.no> <42998036$1@news.broadpark.no> From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 29 May 2005 14:37:44 GMT NNTP-Posting-Host: 24.149.57.125 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.atl.earthlink.net 1117377464 24.149.57.125 (Sun, 29 May 2005 07:37:44 PDT) NNTP-Posting-Date: Sun, 29 May 2005 07:37:44 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:11201 Date: 2005-05-29T14:37:44+00:00 List-Id: Preben Randhol 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.