expr-eval icon indicating copy to clipboard operation
expr-eval copied to clipboard

Add seedable random number generator

Open silentmatt opened this issue 8 years ago • 1 comments

Right now, the random() function is just the built-in Math.random() from the environment. It might be useful to use a deterministic, seedable generator.

Some thought needs to go into how to the implementation since currently, expressions are essentially stateless. Potential options are:

  • Store the current rng state as a property of the expression and maybe provide a seedrandom() function to update it.

  • Pass in and update the seed using a special property in the variables object. Maybe with an invalid variable name so it doesn't conflict with normal variables.

Either way, it's probably useful to be able to share rng state between expressions, so it should be stored in its own object, and should allow for being set explicitly.

silentmatt avatar Sep 20 '17 15:09 silentmatt

This would be nice, I'm quite interested.

Charuru avatar Jan 27 '22 18:01 Charuru