Re: Random Permutations

2003-03-06 Thread Jerzy Karczmarczuk
[EMAIL PROTECTED] wrote: Is there a library routine for random permutations? I didn't find any and did a quick hack... There are many algorithms. One, quite natural and quite fast (n log n; slower than linear, though...) consists in: 1. Generate N random numbers r_k, say, uniform between 0 and 1.

Re: Random Permutations

2003-03-06 Thread Ralf Hinze
Is there a library routine for random permutations? I didn't find any and did a quick hack, which works fine for my application (length of list 100), but what would be a more elegant way? permute :: StdGen - [a] - [a] permute gen [] = [] permute gen xs = (head tl) : permute gen' (hd

Re: Random Permutations

2003-03-06 Thread Andreas Abel
Is there a library routine for random permutations? I didn't find any and did a quick hack, which works fine for my application (length of list 100), but what would be a more elegant way? Well, sorting is a special case of permuting, so my idea was to use the library routine List.sortBy ::

Re: Random Permutations

2003-03-06 Thread Janis Voigtlaender
Andreas Abel wrote: Well, sorting is a special case of permuting, so my idea was to use the library routine List.sortBy :: (a - a - Ordering) - [a] - [a] passing it a comparison function which ignores its arguments and simply returns a random bit when invoked, e.g. permute =

Re: random permutations

2003-03-06 Thread George Russell
Andreas wrote Well, sorting is a special case of permuting, so my idea was to use the library routine List.sortBy :: (a - a - Ordering) - [a] - [a] passing it a comparison function which ignores its arguments and simply returns a random bit when invoked, e.g. permute = sortBy $ \_ _ -