Xref: utzoo comp.lang.prolog:3146 comp.lang.functional:417 Path: utzoo!attcan!uunet!mcsun!ukc!edcastle!aiai!ken From: ken@aiai.ed.ac.uk (Ken Johnson) Newsgroups: comp.lang.prolog,comp.lang.functional Subject: Re: shuffling a list Message-ID: <3373@skye.ed.ac.uk> Date: 6 Sep 90 10:24:18 GMT References: <5056@daffy.cs.wisc.edu> Reply-To: ken@aiai.UUCP (Ken Johnson) Followup-To: comp.lang.prolog Organization: Bugs-R-Us Lines: 23 In article <5056@daffy.cs.wisc.edu> quale@saavik.cs.wisc.edu (Douglas E. Quale) writes: >What is the best way to shuffle a list in a functional language? Here is how I would do it in Prolog 1 Construct a random number generator. 2 Convert the list from the form [a,b,c,..] to a set of pairs of the form [N1-a,N2-b,N3-c] where N1, N2, N3... are random numbers 3 Keysort the list 4 Strip the keys off again. -- Ken -- Ken Johnson, AI Applications Institute, 80 South Bridge, Edinburgh EH1 1HN E-mail ken@aiai.ed.ac.uk, phone 031-225 4464 extension 213 `I have read your article, Mr Johnson, and I am no wiser now than when I started'. -- `Possibly not, sir, but far better informed.'