Skip to content

Instantly share code, notes, and snippets.

@cferdinandi
Created July 5, 2023 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cferdinandi/27eb9fa074cbc40b049db50714ed71c7 to your computer and use it in GitHub Desktop.
Save cferdinandi/27eb9fa074cbc40b049db50714ed71c7 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Random Number</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<script>
/**
* Get a random integer with a minimum and maximum value
* (c) Chris Ferdinandi, MIT License, https://gomakethings.com
* @param {Integer} min The minimum value
* @param {Integer} max The maximum value
* @return {Integer} A random number
*/
function randomNumber (min = 0, max = 1000) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
// Get a random number between 5 and 42
let rand = randomNumber(5, 42);
console.log(rand);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment