Last active
April 2, 2024 20:17
-
-
Save r00k/71433db62959449762e26976261be9b7 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
-- I've successfully written a random generator for Circles. | |
randomCircle : Random.Generator Circle | |
randomCircle = | |
Random.map4 | |
Circle | |
(Random.pair (Random.float -200 200) (Random.float -200 200)) | |
(Random.float minimumRadiusLength maximumRadiusLength) | |
randomColor | |
(Random.float 0 maximumAlpha) | |
-- But now, I want a function that takes a Circle and either | |
-- returns that Circle or generates a random one. | |
sometimesRandomCircle : Circle -> Random.Generator Circle | |
sometimesRandomCircle circle = | |
-- This approach doesn't work. What might? | |
if Random.bool == True then | |
circle | |
else | |
randomCircle | |
-- I understand how to create a *fully* random Circle (or List of random Circles). | |
-- I want to return a random Circle half the time, and return the existing Circle the other half. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's how I'd do it:
Tricky little problem though!