JavaScript random numbers examples

Generating random numbers is a common thing in programming. Here is some examples in JavaScript:

//Basic Random
Math.random();
//From 0 to specific number
Math.random() * 10;
//Removing decimals
Math.floor(Math.random() * 10);
//Random between 5 and 10
Math.floor(Math.random() * 5) + 5;
//Random between 5 and 10 (included 10)
Math.floor(Math.random() * 5) + 6;

Watch this demonstration video:

Here is live preview from Code Pen:

See the Pen JavaScript Random Number by Muhammad Habibie (@habibieamrullah) on CodePen.

Getting boored? Why not playing a game?

Power Block

Tiki Solitaire

Pet Connect

Cake Shop

Jewels Blitz 3

Forest Match

Bike Racing

Aquador

Solitaire Swift

Bubble Shooter Classic HD

Black and white snake

Leave a Reply

Your email address will not be published. Required fields are marked *