I am sampling several arrays and would like to add a seed value to get a consistent result every time its run, now and in the future.
My example:
constant_seed_value = 123456789
["a","b","c"].sample(seed: constant_seed_value ) should return "a" when run every time.
Just pass a Random.new with your seed to sample:
%w[a b c].sample(1, random: Random.new(123456789))
#=> ["a"]
See Array#sample and Random
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With