GHC has an extension to the list comprehensions syntax that replicates the
zipWith, by allowing you to have two generators running in
parallel. Turn on the extension in GHCi like so:
I use the extension below to generate an infinite list of random coordinates (scaled to a 1000x1000 grid) using two different Linear Congruential Generators running in parallel. It should be simple to modify the code below to actually run the generators concurrently using Data Parallel Haskell (although I haven’t had a chance to play with that yet).
1 2 3 4 5 6 7 8
Then we can use another list comprehension, this time with boolean guards, to generate random points that lie within an outer circle (and outside an inner circle):
Finally from GHCi we can use the Gnuplot library to easily plot the points we generated:
…and we get a nice Monte Carlo donut with sprinkles!: