Skip to content

Instantly share code, notes, and snippets.

@shoooe
Created May 9, 2014 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoooe/1022282d815dc6690d5d to your computer and use it in GitHub Desktop.
Save shoooe/1022282d815dc6690d5d to your computer and use it in GitHub Desktop.
Simple algorithm to draw 6 numbers in the range [1..49], implemented in Haskell, as an exercise with Data.Set.
import qualified Data.Set as Set
import System.Random (randomRIO)
import Control.Monad (return)
type Numbers = Set.Set Int
draw :: Int -> Numbers -> IO Numbers
draw i s =
if ((Set.size s) == i) then return s
else do
n <- randomRIO (1, 49)
draw i $ Set.insert n s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment