Haskell Quiz/Sampling

From HaskellWiki
< Haskell Quiz
Revision as of 08:00, 31 October 2006 by KetilMalde (talk | contribs) (comments on similar code)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The object of this problem was to generate a sorted random number sample.

The Problem

Solutions

I did something similar to select random records from a file. Obviously, IO was more time consuming than random generation, so it's probably not a contentder. Code is at [1]. One optimization I do is that if you ask for more than half the range, the problem is inverted.

I also experimented with selecting the k'th "empty slot" in the Set of already chosen numbers, but in the end it turned out to be faster just to keep selecting numbers until a new one was found. With more access to the internals of Data.Set, this could possibly be competitive. --KetilMalde 08:00, 31 October 2006 (UTC)