You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to override rand in Spicy::Seek to allow for the flexibility of making the function deterministic based on an incoming seed. Before submitting a PR, I wanted to propose a couple of ways to implement this.
The easiest is to allow the options hash to be forwarded to rand. Then I can extend the classes and override rand with my own custom implementation:
def seek(opts = {}, &found)
...
- index = rand(rand_min, rand_max)+ index = rand(rand_min, rand_max, opts)
...
end
- def rand(low, high)+ def rand(low, high, opts = {})
range = high - low + 1
low + SecureRandom.random_number(range)
end
Allow passing a lambda as :rand option:
def seek(opts = {}, &found)
...
- index = rand(rand_min, rand_max)+ index = opts[:rand] ? opts[:rand].call(rand_min, rand_max) : rand(rand_min, rand_max)
Any suggestions how I can make this work without otherwise.
Let's discuss below, and I can submit a PR with the preferred implementation.
The text was updated successfully, but these errors were encountered:
I'm trying to override
rand
inSpicy::Seek
to allow for the flexibility of making the function deterministic based on an incoming seed. Before submitting a PR, I wanted to propose a couple of ways to implement this.rand
. Then I can extend the classes and overriderand
with my own custom implementation::rand
option:Let's discuss below, and I can submit a PR with the preferred implementation.
The text was updated successfully, but these errors were encountered: