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

Random function with Fixes #1062

Merged
merged 5 commits into from Feb 1, 2014
Merged

Random function with Fixes #1062

merged 5 commits into from Feb 1, 2014

Conversation

HamptonMakes
Copy link
Member

I read through @nex3's code comments on the random function pull request and implemented the requested changes. I also added some extra tests that weren't requested.

See original pull request here: #968

# Return a decimal between 0 and 1, inclusive of 0, but not 1.
# @return [Sass::Script::Number] A decimal value.
# @overload random($limit)
# Return an integer between 1 and $limit inclusive.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is exclusive of $limit as well.

Also, $limit should be code-quoted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damnit. I misread it. Here is the documentation in Ruby. Good catch, Nathan. Sorry about that. I feel like some other documentation had confused me. Changes coming. http://www.ruby-doc.org/core-2.1.0/Random.html#method-c-rand

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait. Sorry. So, the way that @chriseppstein implemented this, its actually "Random.rand($limit) + 1" So, while the ruby implementation is not inclusive, by adding one, we are making ours inclusive of the limit.

@HamptonMakes
Copy link
Member Author

So, code-quoted the $limit param (plus added its type to the rdoc).

Also, the Random function is inclusive of $limit in this implementation, since its defined in Ruby as "Random.rand(limit) + 1".

if limit
assert_integer limit, "limit"
if limit.value < 1
raise ArgumentError.new("Expected the limit to be 1 or greater")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, this message should be "$limit #{limit} must be greater than or equal to 1".

@nex3
Copy link
Contributor

nex3 commented Jan 7, 2014

Finished reviewing. I'd like Chris's okay on this as well before it goes in.

@nex3 nex3 merged commit 8f406d1 into sass:master Feb 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants