Cleanup
This commit is contained in:
@@ -7,7 +7,7 @@ import Control.Monad.State
|
||||
import Data.List
|
||||
|
||||
randomRanges :: (Random a,RandomGen g) => [a] -> State g a
|
||||
randomRanges xs = join $ takeOne $ f xs
|
||||
randomRanges = join . takeOne . f
|
||||
where
|
||||
f (x:y:ys) = state (randomR (x,y)) : f ys
|
||||
f _ = []
|
||||
@@ -51,12 +51,15 @@ shuffleTail :: RandomGen g => [a] -> State g [a]
|
||||
shuffleTail (x:xs) = (x :) <$> shuffle xs
|
||||
shuffleTail _ = undefined
|
||||
|
||||
-- select elements from a list randomly
|
||||
-- each element has the same independent chance of being selected
|
||||
randomSelectionFromList :: RandomGen g => Float -> [a] -> State g [a]
|
||||
randomSelectionFromList p = filterM $ const $ randProb p
|
||||
randomSelectionFromList = filterM . const . randProb
|
||||
|
||||
randProb :: RandomGen g => Float -> State g Bool
|
||||
randProb p = do p1 <- state $ randomR (0,1)
|
||||
return (p1 < p)
|
||||
randProb p = do
|
||||
p1 <- state $ randomR (0,1)
|
||||
return (p1 < p)
|
||||
|
||||
randInCirc :: RandomGen g => Float -> State g Point2
|
||||
randInCirc maxRad = do
|
||||
|
||||
Reference in New Issue
Block a user