You may throw the die many () times, take the sum of the outcomes and consider the residue class . The distribution on gets closer and closer to a uniform distribution as increases.


You may throw the die once to decide if the final outcome will be even or odd, then throw it again until it gives an outcome different from six, that fixes the residue class . In such a way you generate a uniform distribution over with tosses, in average.


If you are allowed to throw the die in a wedge, you may label the edges of the die with the numbers in and mark two opposite edges as "reroll". In such a way you save exactly one toss, and need just tosses, in average.


Obviously, if you are allowed to throw the die in decagonal glass you don't even need the die, but in such a case the lateral thinking spree ends with just toss. Not much different from buying a D10, as Travis suggested.


At last, just for fun: look at the die, without throwing it. Then look at your clock, the last digit of the seconds. Add one. tosses.

Answer from Jack D'Aurizio on Stack Exchange
🌐
Random Word Generator
randomwordgenerator.com › number.php
Random Number Generator — Easy Number Picker
We'd also love to hear any suggestions you may have to make the tool better for everyone. As random as we can make it! We use javascript's internal Math.random() function which returns a Psuedo-random number in the range 0 to less than 1.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › find-the-missing-number
Find the Missing Number - GeeksforGeeks
Input: arr[] = [1, 2, 3, 5] Output: 4 Explanation: Here the size of the array is 4, so the range will be [1, 5]. The missing number between 1 to 5 is 4
Published   April 19, 2025
Discussions

Generate random number between two numbers in JavaScript - Stack Overflow
Is there a way to generate a random number in a specified range with JavaScript ? For example: a specified range from 1 to 6 were the random number could be either 1, 2, 3, 4, 5, or 6. More on stackoverflow.com
🌐 stackoverflow.com
Creating a random number within a defined range using JavaScript
How can I make JavaScript pick a random number from a specific set? I’m working on a little project and I need to get JavaScript to choose a number at random. But here’s the thing: I want it to pick from a certain group of numbers, not just any number. Let’s say I want it to pick a number ... More on community.latenode.com
🌐 community.latenode.com
0
0
March 19, 2025
Set variable with random number
Hi! An easy question. How can I set a variable with a random number? Thank you for your help! More on forum.uipath.com
🌐 forum.uipath.com
1
2
June 6, 2017
Generating random number between 1 to 10
Generating random number between 1 to 10. Learn more about random numbers More on mathworks.com
🌐 mathworks.com
4
0
July 1, 2014
People also ask

How random is this Random Number Generator?
As random as we can make it! We use javascript's internal Math.random() function which returns a Psuedo-random number in the range 0 to less than 1. We then just transform that number into an integer. The internals are complicated but rest assured, these numbers are as random as it gets.
🌐
randomwordgenerator.com
randomwordgenerator.com › number.php
Random Number Generator — Easy Number Picker
Do you have a Random Number Generator mobile app?
No, we don't have a mobile application, but our website is 100% mobile friendly.
🌐
randomwordgenerator.com
randomwordgenerator.com › number.php
Random Number Generator — Easy Number Picker
What is the maximum number you can use in your Number Generator?
The maximum number that you can use in the random number generator is 1000000000 (1 billion)
🌐
randomwordgenerator.com
randomwordgenerator.com › number.php
Random Number Generator — Easy Number Picker
Top answer
1 of 16
103

You may throw the die many () times, take the sum of the outcomes and consider the residue class . The distribution on gets closer and closer to a uniform distribution as increases.


You may throw the die once to decide if the final outcome will be even or odd, then throw it again until it gives an outcome different from six, that fixes the residue class . In such a way you generate a uniform distribution over with tosses, in average.


If you are allowed to throw the die in a wedge, you may label the edges of the die with the numbers in and mark two opposite edges as "reroll". In such a way you save exactly one toss, and need just tosses, in average.


Obviously, if you are allowed to throw the die in decagonal glass you don't even need the die, but in such a case the lateral thinking spree ends with just toss. Not much different from buying a D10, as Travis suggested.


At last, just for fun: look at the die, without throwing it. Then look at your clock, the last digit of the seconds. Add one. tosses.

2 of 16
42

Write out the base- decimals of through .

$$\begin{array}{cc} \frac{0}{10} & = 0.00000000\dots\\ \frac{1}{10} & = 0.03333333\dots\\ \frac{2}{10} & = 0.11111111\dots\\ \frac{3}{10} & = 0.14444444\dots\\ \frac{4}{10} & = 0.22222222\dots\\ \frac{5}{10} & = 0.30000000\dots\\ \frac{6}{10} & = 0.33333333\dots\\ \frac{7}{10} & = 0.41111111\dots\\ \frac{8}{10} & = 0.44444444\dots\\ \frac{9}{10} & = 0.52222222\dots\\ \frac{10}{10} & = 1.00000000\dots\\ \end{array}$$

Treat rolls of a as a . As you roll your -sided die, you are generating digits of a base- decimal number, uniformly distributed between and . There are gaps in between the fractions for , corresponding to the uniformly random outcomes you are looking for. You know which outcome you are generating as soon as you know which gap the random number will be in.

This is kind of annoying to do. Here's an equivalent algorithm:

Roll a die : Roll a die : Roll a die : Roll a die

One sees that:

  • returns with probability and with probability .
  • returns with probability , with probability , and with probability .
  • returns with probability and with probability .

Overall, it produces the outcomes each with probability.

Procedures and are expected to require rolls. Procedure is expected to require rolls. So the main procedure is expected to require rolls.

🌐
Programiz
programiz.com › javascript › examples › random-between-numbers
Javascript Program to Generate a Random Number Between Two Numbers
In JavaScript, you can generate a random number with the Math.random() function. Math.random() returns a random floating-point number ranging from 0 to less than 1 (inclusive of 0 and exclusive of 1)
Find elsewhere
🌐
JavaScript in Plain English
javascript.plainenglish.io › how-to-generate-unique-random-numbers-between-1-and-100-with-javascript-ffa29c389833
How to Generate Unique Random Numbers Between 1 and 100 with JavaScript | by John Au-Yeung | JavaScript in Plain English
April 17, 2023 - Since Math.random only generates numbers between 0 and 1, we’ve to multiply the returned result by 100, round it down with Math.floor and add 1 to it. If the number isn’t already in arr as returned by indexOf , then we call push to add it to… ... New JavaScript and Web Development content ...
🌐
W3Schools
w3schools.com › js › js_random.asp
JavaScript Random
Multiplying by 10 gives a number from 0 up to but not including 10. Adding 1 shifts that range to 1 up to but not including 11. Math.floor() then rounds down, so you get an integer between 1 and 10.
🌐
Latenode
community.latenode.com › other questions › javascript
Creating a random number within a defined range using JavaScript - JavaScript - Latenode Official Community
March 19, 2025 - How can I make JavaScript pick a random number from a specific set? I’m working on a little project and I need to get JavaScript to choose a number at random. But here’s the thing: I want it to pick from a certain group of numbers, not just any number. Let’s say I want it to pick a number ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › random
Math.random() - JavaScript | MDN
The Math.random() static method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random ...
🌐
Oreate AI
oreateai.com › blog › unlocking-randomness-your-guide-to-generating-numbers-in-javascript › db3114ed61eb95599a25e7aa3ae32c40
Unlocking Randomness: Your Guide to Generating Numbers in JavaScript - Oreate AI Blog
February 9, 2026 - Math.random() * (max - min + 1): Multiplying our random decimal by this range scales it up. So, instead of a number between 0 and 1, we now have a number between 0 and (almost) 11.
🌐
Medium
medium.com › @ryan_forrester_ › random-number-in-a-range-in-javascript-464dfeddf8d4
Random Number in a Range in JavaScript | by ryan | Medium
September 11, 2024 - function getRandomNumberInRange(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } const randomNum = getRandomNumberInRange(1, 10); console.log(randomNum); // Output: a random integer between 1 and 10
🌐
LaunchCode
education.launchcode.org › intro-to-professional-web-dev › appendices › math-method-examples › random-examples.html
Math.random Examples — Introduction to Professional Web Development in JavaScript documentation
floor = 0, ceil = 1, round = 0 ... Math.random() by 10, applying the floor method gives numbers between 0 and 9. Using the ceil method shifts the range up one digit, generating values between 1 and 10....
🌐
DC Lottery
dclottery.com › games › dc-5
DC 5 | DC Lottery
1 week ago - Why not let the DC Lottery website's random number generator give you some ideas? ... Powerball® tickets cost $2 and are available at most DC Lottery retailers. Add the Power Play® option... ... Lotto America is an exciting jackpot game, starting at $2 million! Other non-jackpot prizes range from $2 to... DC Keno is fast, simple, fun, and offers a chance to win up to $1,000,000.
🌐
UiPath Community
forum.uipath.com › help
Set variable with random number - Help - UiPath Community Forum
June 6, 2017 - Hi! An easy question. How can I set a variable with a random number? Thank you for your help!
🌐
MathWorks
mathworks.com › matlabcentral › answers › 139713-generating-random-number-between-1-to-10
Generating random number between 1 to 10 - MATLAB Answers - MATLAB Central
July 1, 2014 - Hi everyone, I want to generate a random number between 1 to 10 for 10 loop iteration, with this code section of mine but i want that each time it generate a different number. Forexample if 2 ...
🌐
CoreUI
coreui.io › blog › how-to-generate-a-random-number-in-javascript
Javascript Random - How to Generate a Random Number in JavaScript? · CoreUI
April 16, 2024 - Often, you’ll need a random number ... between two values, you can use this function: const getRandomNumber = (min, max) => { return Math.random() * (max - min) + min } // Random number between 5 and 10 const randomNumber = ...
🌐
Medium
josephcardillo.medium.com › using-math-random-in-javascript-c49eff920b11
Using Math.random() in JavaScript - Joe Cardillo - Medium
January 31, 2022 - In JavaScript, to get a random number between 0 and 1, use the Math.random() function. ... If you want a random number between 1 and 10, multiply the results of Math.random by 10, then round up or down.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Basic JavaScript - Generate Random Whole Numbers with JavaScript - JavaScript - The freeCodeCamp Forum
April 18, 2023 - Tell us what’s happening: The instructions for this lesson ask you to use the Math.floor(Math.random()) * N to generate and return a random whole number between 0 and 9 When I return Math.floor(Math.random()*9) it is…
🌐
Reddit
reddit.com › r/learnprogramming › generate a random number within a range - how does the math work?
r/learnprogramming on Reddit: Generate A Random Number Within A Range - How Does the Math Work?
February 4, 2022 -

Hi all,

I'm learning JS through FCC and it's going okay so far. I'm not a very mathematically inclined person, however, so I struggle with some concepts.

I'm struggling to understand how the following code works;

Math.floor(Math.random() * (max - min + 1)) + min

I tried writing out an example on paper and used 10 and 5 as max and min respectively.

Math.floor(Math.random() * (10 - 5 + 1)) + 5

wouldn't this mean that I can get numbers higher than the max though? Say I get a randomly generated 0.99; well 0.99 * (6) + 5 = 10.94 which is greater than my max of 10?

Am I doing this wrong?

🌐
SitePoint
sitepoint.com › blog › javascript › how to generate random numbers in javascript with math.random()
Generating Random Numbers in JavaScript with Math.random()
November 7, 2024 - To use it, simply enter Math.random() ... want a random number that’s bigger than 1? Easy: all you need to do is multiply by a scale factor to scale it up — for example, multiplying the result by 10 will produce a value between ...