This commit is contained in:
2022-02-13 17:29:32 +00:00
parent eba1713895
commit 40f1d987cb
21 changed files with 109 additions and 171 deletions
+7 -4
View File
@@ -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