Skip to content

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

@mbostock

Description

@mbostock

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions