Fork me on GitHub
#cljs-dev
<
2023-06-01
>
Chris McCormick06:06:58

Sorry to be late to the rand-uuid party but I just wanted to flag that for all the rand* funtions in cljs you sometimes want cryptographic security and other times you want complete determinism, depending on the application. In the past I've used https://github.com/davidbau/seedrandom which can give you both cryptographically secure (seeded from webcrypto) or deterministic (seeded from a fixed or user supplied seed). It can replace the global Math.random with it's own RNG which is useful if you want to use e.g. rand-nth or random-sample in a Roguelike game or Melody Generator where perfect determinism during procgen is important, or rand-uuid in a cryptographic application where you want the opposite. I guess what I am getting at is it would be cool if instead of having to overwrite the global Math.random which might cause other issues (often security issues), you could instead somehow tell all the rand* functions which RNG to use, either by re-binding something or as an argument to the functions themselves e.g. (rand-nth [1 2 3] my-rng-fn) . So by default they could use Math.random() but then there could be some way for the user to specify their own deterministic or cryptographically secure RNG isntead. Sorry if this is unhelpful but I wanted to put it out there as I have run into this a few times in the field! 😅

👍 2