# Haskell Quiz/Sampling

### From HaskellWiki

< Haskell Quiz(Difference between revisions)

KetilMalde (Talk | contribs) (comments on similar code) |
(+cat) |
||

Line 1: | Line 1: | ||

− | The object of this problem was to generate a sorted random number sample. |
+ | The object of this problem is to generate a sorted random number sample. |

==The Problem== |
==The Problem== |
||

Line 10: | Line 10: | ||

* [[Haskell Quiz/Sampling/Solution Kuklewicz|Chris Kuklewicz]] -- linear performance |
* [[Haskell Quiz/Sampling/Solution Kuklewicz|Chris Kuklewicz]] -- linear performance |
||

− | 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 [http://www.ii.uib.no/~ketil/bioinformatics/repos/rselect/RSelect.lhs]. One optimization I do is that if you ask for more than half the range, the problem is inverted. |
+ | 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 contender. Code is at [http://www.ii.uib.no/~ketil/bioinformatics/repos/rselect/RSelect.lhs]. 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. --[[User:KetilMalde|KetilMalde]] 08:00, 31 October 2006 (UTC) |
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. --[[User:KetilMalde|KetilMalde]] 08:00, 31 October 2006 (UTC) |
||

+ | |||

+ | [[Category:Haskell Quiz|Sampling]] |

## Revision as of 10:26, 13 January 2007

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

## 1 The Problem

## 2 Solutions

- Dan Doel
- Chris Kuklewicz -- linear performance

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 contender. 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)