🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #1165

Re: shuffling a list

#1165
From: Ken Johnson
Date: Thu, 06 Sep 1990 10:24
23 lines
1107 bytes
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.'
Technical Details
Message-ID: <3373@skye.ed.ac.uk>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!edcastle!aiai!ken
References: <5056@daffy.cs.wisc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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