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

feat(random): Adds a function that generates a random floating-point number between the minimum and maximum. #53

Merged
merged 17 commits into from
Jun 15, 2024

Conversation

sossost
Copy link
Contributor

@sossost sossost commented Jun 14, 2024

close #51

I have added a function to generate a random floating point number between the minimum and maximum values input.

Below is a screenshot of the benchmark.
image

If the min and max are the same, it's returning the min value, just like lodash, but I don't know which is better, throwing an exception or not.

I'll also be working on the randomInt function based on feedback from this PR.

Copy link

vercel bot commented Jun 14, 2024

@sossost is attempting to deploy a commit to the Toss Team on Vercel.

A member of the Team first needs to authorize it.

@codecov-commenter
Copy link

codecov-commenter commented Jun 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (50c3585) to head (3fe4253).
Report is 393 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main       #53   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           46        47    +1     
  Lines          223       227    +4     
  Branches        22        23    +1     
=========================================
+ Hits           223       227    +4     

@raon0211
Copy link
Collaborator

raon0211 commented Jun 15, 2024

Hello, thanks for your contribution! This is a great pull request.

Meanwhile, I think the result of random(5, 0) is hard to tell. Why not we throw an error, like throw new Error("The maximum value must be greater than the minimum value.")?

if (minimum > maximum) {
  throw new Error("The maximum value must be greater than the minimum value.");
}

@sossost
Copy link
Contributor Author

sossost commented Jun 15, 2024

Good opeanion, it's more consistent and clear than the old way. I've updated the code in that direction.

Minimum (inclusive) maximum (exclusive), so for consistency, it will also throw an exception if the minimum and maximum are the same.

if (minimum >= maximum) {
   throw new Error('Invalid input: The maximum value must be greater than the minimum value.');
}

Copy link
Collaborator

@raon0211 raon0211 left a comment

Choose a reason for hiding this comment

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

Thanks for your great contribution!

@raon0211 raon0211 merged commit 65a65ea into toss:main Jun 15, 2024
6 of 7 checks passed
@sossost
Copy link
Contributor Author

sossost commented Jun 15, 2024

Thanks too!

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.

Support for random
3 participants