Skip to content

Instantly share code, notes, and snippets.

@tzwel
Last active June 20, 2022 03:40
Show Gist options
  • Save tzwel/b7e75dc7115245fd38ea82c086742a6e to your computer and use it in GitHub Desktop.
Save tzwel/b7e75dc7115245fd38ea82c086742a6e to your computer and use it in GitHub Desktop.
const numjs = (function () {
// Get a random number in range, accept generating multiple numbers optionally converted to a single Number
function range(min, max, times = 1, convert = false) {
let generatedNumber = Math.floor(Math.random() * (max - min + 1) + min)
if (times > 1) {
for (let i=1; i< times; i++) {
generatedNumber += Math.floor(Math.random() * (max - min + 1) + min).toString()
}
}
if (convert) {
generatedNumber = Number(generatedNumber)
}
return generatedNumber
}
// Return current unix time timestamp
function time() {
return Date.now()
}
return { range, time }
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment