tiltRandomly :: (a, a) -> Plane a -> Rand g (Plane a)
tiltRandomly (lo, hi) p =
if (lo > hi)
then error "tiltRandomly: lo > hi"
else case (listToMaybe . liftM catMaybes . sequence . repeat $ do
v <- V2 <$> randomR (0, hi) <*> randomR (0, hi)
if magnitude v <= hi && magnitude v >= lo
then $ Just v
else Nothing) of
Just v -> return $ tilt v p
Nothing -> error "tiltRandomly: uh wow that infinite list sure evaluated fast huh"
i think this is the first time i've explicitly used laziness to my advantage
but of course it's in a messy partial function. also, bad news if you set lo
& hi
such that it takes like eight million tries to get a value that passes! laziness sure is a thing.