Last active
February 4, 2017 17:23
-
-
Save deque-blog/9043d9a077f0a7c051cc921fcf3804bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perturb :: (Integral n) => n -> StdGen -> StdGen | |
perturb n rand0 = | |
foldl | |
(\rand b -> vary b rand) -- Vary generator based on digit value | |
(vary (n < 0) rand0) -- Vary generator based on sign | |
(digits (abs n)) -- Decompose a positive number in digits | |
where | |
vary digit rand = | |
(if digit then snd else fst) | |
(split rand) | |
digits = | |
map ((== 0) . (`mod` 2)) | |
. takeWhile (> 0) | |
. iterate (`div` 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment