Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A proposal to better random number generation #62

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/forgery/extensions/range.rb
Expand Up @@ -9,7 +9,7 @@ def unextend
def random
Integer(first) && Integer(last)
raise ArgumentError if first > last
Kernel.rand(last - first + (exclude_end? ? 0 : 1)) + first
Random.rand self
rescue ArgumentError
Forgery::Extend(to_a).random
end
Expand Down
4 changes: 2 additions & 2 deletions spec/extensions/range_spec.rb
Expand Up @@ -27,7 +27,7 @@
end

it "should not return the maximum at excluded range" do
expect(Kernel).to receive(:rand).with(9).and_return(8)
expect(Forgery::Extend(0...9).random).not_to be_equal 9
Random.should_receive(:rand).with(0...9).and_return(8)
Forgery::Extend(0...9).random.should_not be_equal 9
end
end