Hi,
I too, am super interested in games in Clojure. My other background is cryptography, so I break out the crypto. I would say that you don’t really want a PRG, but you might want a PRF instead. (If that doesn’t mean anything to you, don’t worry, read on.) My favorite cryptographic hash function, BLAKE2, has a number of cool features that might help. If you have some description of the thing that you want and a random seed, you can produce a number from which you can then go on and generate whatever you want. This answers your “sub-seed” question: blake2(master_seed, “room 1”) and blake2(master_seed, “room 2”) will be completely different values. However, you can compute blake2(master_seed, “room 1”) at any later point, and it will still be the same value. This makes all of the problems of sharing, ordering… go away. No more state :) This does mean passing a seed around in your game state, but it seems evident to me that your seed is indeed a fundamental property of your game state, so I don’t think that’s a bad thing. While BLAKE2 is of course significantly stronger than what you need for a game, it is ridiculously fast [1]. In case you’re worried about speed (you most likely shouldn’t be), SipHash is still significantly stronger than what you need (nearly cryptographic strength), but is competitive in speed with non-cryptographic hash functions like CityHash, Murmur2/3.... Neither BLAKE2 nor SipHash nor other PRFs typically come with the randomness utility features you would typically want, like random selection, weighted random selection, random variable according to a distribution… Hopefully those things are available in a way that lets you separate the concern of “generate n pseudorandom bits” and “use those bits to produce a value”. Of course, other PRNG algorithms like MT also don’t solve this problem: they just give you some random-looking bytes, just like BLAKE2/SipHash :) BLAKE2 is exposed with a nice Clojure API through my caesium library. I don’t know of any easily available SipHash implementations, but I can’t imagine it’s very hard to get it running. There’s a Java implementation, and various Lisp implementations that shouldn’t be terribly hard to port to Clojure. [1]: https://blake2.net/ [2]: https://131002.net/siphash/ hth lvh
signature.asc
Description: Message signed with OpenPGP using GPGMail