dry-rb / dry-effects

Algebraic effects in Ruby
https://dry-rb.org/gems/dry-effects/
MIT License
112 stars 20 forks source link

Create random generator from options #69

Closed flash-gordon closed 4 years ago

flash-gordon commented 4 years ago

This adds arguments to the random provider. These values are used to build a random generator, similar to how the timestamp provider works.

Passing the same seed produces the same results:

with_random(seed: 123) { ... }

When a proc is passed, it's used to get the next value:

with_random(proc { |prev_value = 0.0| prev_value + 0.1 }) { ... }

Both options are useful for testing random values.