[m-dev.] diff: random permutations

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Feb 9 15:54:07 AEDT 2000


On 04-Jan-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> > 	(1) a function for computing a list of the first N integers
> > and
> > 	(2) a predicate for computing a random permutation of a list
> > ?
> > 
> > I think those procedures would probably be more generally useful
> 
> I agree, although there may well be a place for predicates computing
> 	(3) random samples of integers in a range and
> 	(4) random permutations of the above.

I presume by (4) you mean

 	(4) random permutations of integers in a range

not

	(4') random permutations of random samples of integers in a range

since (4') would be equivalent to (3).

Anyway, if we provide a `..' function for computing a list
containing a range of integers, e.g. 5 `..` 10 = [5,6,7,8,9,10]
(this is a slight generalisation of (1) above),
as Michael Day suggested, and a `random_permutation' predicate ((2) above),
then you can easily achieve (4) by composing these two.
Note that (4) is a generalization of what the random__permutation
predicate that Zoltan added to random.m does; random__permutation
(like random__random) assumes that the range you want starts at 0.

Similarly (3) could be achieved by repeated calls to a
predicate for getting one random integer in a range.
I don't think it is worth adding special support for
that to the random module, though we may want to consider
adding higher-order procedures for iteration to the
standard library.

So my original suggestion, modified by adding a `..' function as suggested
by Michael Day, will handle (1) and (2) directly, and would support (4)
by simple composition.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list