I've been working on some projects (roguelikes, story-generators) that often have a reason to have a random outcome for things like procedurally generating a map. Ideally, they would be deterministically psuduorandom, so that I can generate the same results from the same seed. The part I'm having trouble with is figuring out what method to use to implement this in a functional way.
The naive approach that first occurred to me was to pass a PRNG and seed value into each function. That would certainly keep the functions referentially transparent. But it would also require either rewriting a bunch of functions that don't directly use the randomness themselves or adding the RNG as part of the map that's already being passed. Plus, the seed should probably vary (deterministically) between calls to the subfunctions. It's not too useful if all the rooms on a map have the same type because they all pulled their die roll from the same-nth result of the exact same seed. Maybe the seed could be created from the contents of the vector or a UUID of a map object or something? The other suggestion I've run across is to rebind something like clojure.data.generators/*rnd* for each high-level procedural generation call. I think this requires the generation to be single threaded and otherwise deterministic. At the moment I don't feel like I know enough about how things work under the hood to say if this a good idea or not. I've poked around at the bigml.sampling and clojure.data.generators libraries, which look useful for dealing with some of this, but I haven't come across anything that directly addresses what kind of architecture to use for deterministic randomness. This may be my inexperience. I feel like I may be a bit too close to the problem, and I can't quite see what the idiomatic answer is. Re-read SICP? Implement some kind of monad? Just bite the bullet and pass the RNG+seed? Find the secret pure functional library everyone is using for repeatable stochastic simulations? Does anyone have any advice on this? Or prior experience with approaches that work? What are some best practices for approaching deterministic simulations in an idiomatic, functional way? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.