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

randomInt([min = 0, ]max) #26

Closed
mbostock opened this issue May 31, 2019 · 0 comments
Closed

randomInt([min = 0, ]max) #26

mbostock opened this issue May 31, 2019 · 0 comments

Comments

@mbostock
Copy link
Member

mbostock commented May 31, 2019

We should have a randomInt method that returns an integer greater than or equal to min and less than max.

function randomInt(min, max) {
  if (arguments.length < 2) max = min, min = 0;
  min = Math.floor(min);
  max = Math.floor(max) - min;
  return () => Math.floor(min + Math.random() * max);
}
@mbostock mbostock mentioned this issue Jul 30, 2019
29 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant