Skip to content

Instantly share code, notes, and snippets.

@slavkapiyavka
Created April 5, 2024 12:57
Show Gist options
  • Save slavkapiyavka/7faee87571364197f2c381e140de2103 to your computer and use it in GitHub Desktop.
Save slavkapiyavka/7faee87571364197f2c381e140de2103 to your computer and use it in GitHub Desktop.
const getRandomPositiveNumber = (from, to) => {
if (from === to) {
return from;
}
if (from <= 0 || to <= 0) {
return 0;
}
if (from > to) {
[from, to] = [to, from];
}
const min = Math.ceil(from);
const max = Math.floor(to);
return Math.floor(Math.random() * (max - min + 1)) + min;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment