Random Number Generator

Generate a random number between
and .
Include numbers after the decimal point.

Information for Programmers

JavaScript formula for generating a random number

Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;

Math.floor() vs Math.round()

Why use Math.floor() and not Math.round()? As an example, let's say that you want to generate numbers in the range of 0 to 2. If you do Math.round(0.4) you get 0, and if you do Math.round(0.5) you get 1. On the other end of your random range, if you do Math.round(1.4) you get 1, and if you do Math.round(1.5) you get 2.

But this means that you are half as likely of getting 0 and 2 as you are of getting 1. Look at this number line:


|        0         |                  1                    |          2           |
0.0-0.1-0.2-0.3-0.4-0.5-0.6-0.7-0.8-0.9-1.0-1.1-1.2-1.3-1.4-1.5-1.6-1.7-1.8-1.9-2.0

Notice that the space for 0 and 2 is smaller than the space for 1. If you wanted to have an equal chance of getting 0, 1, and 2 using Math.round(), you would have do some manipulation with decimal numbers in your random number formula. However, there is an easier way.

If you use Math.floor() on numbers like 0.4, 1.4, and 2.4 for example, this is the number line that you get:


|                  0                   |                   1                   |                   2                  |
0.0-0.1-0.2-0.3-0.4-0.5-0.6-0.7-0.8-0.9-1.0-1.1-1.2-1.3-1.4-1.5-1.6-1.7-1.8-1.9-2.0-2.1-2.2-2.3-2.4-2.5-2.6-2.7-2.8-2.9

As you can see, each of the three numbers in the 0 to 2 range has the same amount of space on this number line, making each one equally likely when you put a random number into Math.floor().

Get help with games!
Pokémon Sun and Moon Pokémon Go Zero Escape: Zero Time Dilemma Yo-Kai Watch Animal Crossing: Happy Home Designer Fire Emblem Fates Story of Seasons Pokémon Omega Ruby and Alpha Sapphire Disco Zoo The Legend of Zelda: A Link Between Worlds Pokémon X and Y Animal Crossing: New Leaf Nimble Quest Zero Escape: Virtue's Last Reward Pokémon Black 2 and White 2 Pocket Planes The Legend of Zelda: Skyward Sword Professor Layton's London Life Tiny Tower Pokédex 3D Guide Portal 2 Nintendogs + Cats Guide Find Mii 3DS Walkthrough Super Scribblenauts Walkthrough Pokémon Black and White Walkthrough Pocket Frogs Guide Nine Hours, Nine Persons, Nine Doors Walkthrough Zero Escape The Legend of Zelda: Spirit Tracks Walkthrough Animal Crossing: Wild World Guide Pokémon HeartGold and SoulSilver Walkthrough Dragon Quest IX The Sims 3 Guide Final Fantasy Tactics A2: Grimoire of the Rift Portal Walkthrough Contact for Nintendo DS Walkthrough White Chamber Walkthrough The Legend of Zelda: The Minish Cap Walkthrough Blue Chamber Walkthrough Crimson Room Walkthrough Viridian Room Walkthrough EVE Online Guide Final Fantasy Tactics Advance Walkthrough The Legend of Zelda: The Wind Waker Walkthrough Pokémon Ruby, Sapphire, Emerald Metroid Fusion Walkthrough The Legend of Zelda: Oracle of Seasons The Legend of Zelda: Oracle of Ages The Legend of Zelda: Majora's Mask The Legend of Zelda: Ocarina of Time Walkthrough Dink Smallwood Pokémon Tales of Phantasia Walkthrough Terranigma Chrono Trigger EarthBound Walkthrough QR Code Tutorial Final Fantasy 3/6 Walkthrough Illusion of Gaia Secret of Mana Walkthrough The Legend of Zelda: Link's Awakening DX Soul Blazer Walkthrough The Legend of Zelda: A Link to the Past Walkthrough Battle of Olympus Maniac Mansion (NES) Castlevania II: Simon's Quest Zelda II: The Adventure of Link Walkthrough Picross Tutorial The Legend of Zelda Sudoku Chess