Skip to content
New issue

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

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

Already on GitHub? # to your account

Can't pass zero (0) to the default rand method (Faker override) #976

Closed
gssbzn opened this issue Jul 11, 2017 · 1 comment
Closed

Can't pass zero (0) to the default rand method (Faker override) #976

gssbzn opened this issue Jul 11, 2017 · 1 comment

Comments

@gssbzn
Copy link
Contributor

gssbzn commented Jul 11, 2017

The changes introduced with eace5e6 broke things like

Faker::Lorem.sentence(2, false, 0)

Even though documentation says it should be possible

According to the Random documentation rand(max) returns a value between zero and max (not inclusive), and thus negative or zero are not valid parameters

There's a couple of ways to fix this and wanted to do it according to the project's recommendations before submitting a PR

  • Should the documentation be updated to reflect this (passing 1 to Random::DEFAULT.rand always returns zero (0)),
  • Should this behavior be fixed and allow for zero on rand, or at least the current method signatures that allow zero?

Thx

@stympy
Copy link
Contributor

stympy commented Jul 11, 2017

I vote for keeping the existing documentation and (old) behavior by allowing zero in the arguments list and then handing Kernel.rand the passed argument + 1.

stympy pushed a commit that referenced this issue Jul 12, 2017
Improve `Faker::Base.rand` to handle zero (0) as max value and restore
documented behaviour for some methods that depend on it

Closes #976
landongrindheim pushed a commit to landongrindheim/faker that referenced this issue Oct 7, 2017
Improve `Faker::Base.rand` to handle zero (0) as max value and restore
documented behaviour for some methods that depend on it

Closes faker-ruby#976
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants