Generate Javascript Random Number between 1 and 10


Generate Javascript Random Number between 1 and 10

Hi friends, in this tutorial you will learn how to generate javascript random number between 1 and 10 which means you have to return all the numbers except 10 which means zero to nine. In order to generate random numbers, you should have the idea of two javascript functions as mentioned below

  1. Math.random()
  2. Math.floor()

Math.random( ):- This function always returns the numbers less than one which means it produces the numbers between zero and one or you can say including zero and excluding one.

Example:-

<html>
<head>
<title>Javascript random number example</title>
</head>
<body>
	<h3>Below is a random number using Math.random()</h3>
    <p id="random"></p>
<script type="text/javascript">
	document.getElementById("random").innerHTML = Math.random();
</script>
</body>
</html>

Output:-

Below is a random number using Math.random()

0.7600114421439201

Math.floor( ) :- This function returns the number from the left side of a floating point number as shown in the example below

Example:-

<html>
<head>
<title>Javascript random number example</title>
</head>
<body>
	<h3>Apply Math.floor() to 1.3</h3>
    <p id="floor"></p>
<script type="text/javascript">
	document.getElementById("floor").innerHTML = Math.floor(1.3);
</script>
</body>
</html>

Output:-

Apply Math.floor() to 1.3

1

Also read, Object in Javascript with example

Two ways to generate a javascript random number between 1 and 10

  • Using Math.random() function with the help of Math.floor()
  • Using javascript function with the help of minimum and maximum numbers.

Using Math.random() function with Math.floor()

If you want to generate a random number between 1 and 10 that means you are going to display the numbers from 0 to 9. In order to do so, you can use the Math.random() function with Math.floor() as shown in the example below

Example:-

<html>
<head>
<title>Javascript random number example</title>
</head>
<body>
    <h3>Random number between 1 and 10</h3>
    <p id="random_number"></p>
<script type="text/javascript">
	document.getElementById("random_number").innerHTML = Math.floor(Math.random()*10);
</script>
</body>
</html>

Output:-

Random number between 1 and 10

4

Using javascript function with minimum and maximum number

As we all know that we can return any number or output inside the javascript function. Here, we will use a function using the formula as shown in the below example to return the numbers from 0 to 9.

Formula:- Math.floor(Math.random() * (max – min) ) + min;

Example:-

<html>
<head>
<title>Javascript random number example</title>
</head>
<body>
    <button type="button" onclick="genearteRandomNumber()">Click here to generate random number between 1 and 10</button>
    <p id="random_number_using_function"></p>
<script type="text/javascript">
	function genearteRandomNumber()
	{
		document.getElementById("random_number_using_function").innerHTML = Math.floor(Math.random()*(10-1))+1;
	}
</script>
</body>
</html>

Output:-

Conclusion:- I hope this tutorial will help you to understand the concept of producing a random number. If there is any doubt then please leave a comment below


Leave a Comment

KUPU178

KUPU178

RATU311

THOR311 TOTO4D

KUPU178

Live Casino Roullate

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

THOR311

THOR311

THOR311

RATU311

CERI188

DAFTAR KUPU178

LINK DAFTAR CERI188

CERI188

sabung ayam online

APK KUPU178

KUPU178

CERI188

CERI188

RATU311

KUPU178

THOR311 DOMINO QQ

judi bola online

Mix Parlay

CERI188

CERI188

CERI188

KUPU178

RATU311

live casino online

RATU311

Mix Parlay

Sabung Ayam Online

Slot PG Soft

CERI188

RATU311

RATU311

RATU311

RATU311

CERI188

THOR311

CERI188

THOR311

RATU311

THOR311

Game Thor311

THOR311

HOKI311

live casino

sv388

HOKI311

HOKI311

slot mahjong

Thor311 Alternatif

RATU311

HOKI311

HOKI311

HOKI311

HOKI311

CERI188

THOR311 RESMI

THOR311 AKSES

THOR311

THOR311 RTP

RATU311

RATU311

THOR311

parlay

HOKI311

RATU311

THOR311

Ceri188

Thor311 Game Online

Thor311 Aplikasi

LINK CERI188

RATU311 NONTON BOLA

RATU311

CERI188 Link RTP LIVE

THOR311

Thor311 Live Casino

CERI188

akses VIP THOR311

THOR311

link daftar THOR311

THOR311

situs thor311

THOR311 LOGIN

THOR311

RATU311

RATU311

HOKI311 Link SABUNG AYAM RESMI

HOKI311 Link QRIS EWALLET

RATU311

LINK CERI188

parlay

HOKI311 Link RTP Gacor

THOR311

RATU311

HOKI311 Link Apk Resmi

KUPU178

RATU311

RATU311

CERI188

CERI188 Situs Spaceman Terbaik 2026

KUPU178 Link Daftar

CERI188

CERI188

CERI188

CERI188

CERI188

HOKI311

THOR311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

CERI188 Live Casino

HOKI311 Lapak Arena Slot

RATU311 judi bola

CERI188 Live Casino

HOKI311 Link Spaceman Online

HOKI311 Link Daftar Resmi

CERI188 Toto SGP Online

KUPU178

KUPU178

KUPU178

KUPU178

HOKI311 TEMBAK IKAN ONLINE

RATU311

CERI188 PANDUAN MAXWIN SLOT ONLINE

RATU311

RATU311

KUPU178

HOKI311 Link Login Alternatif

HOKI311 Live Casino Online

HOKI311 Situs Slot Gacor

THOR311

THOR311

situs judi bola

Ceri188 Game Online

CERI188

link login CERI188

link login CERI188

CERI188

link login CERI188

link login CERI188

link daftar CERI188

THOR311

HOKI311

HOKI311

CERI188

CERI188

CERI188

parlay

THOR311

RATU311

RATU311

HOKI311

HOKI311

parlay

HOKI311

RATU311

THOR311

KUPU178

HOKI311

KUPU178

KUPU178

KUPU178

HOKI311

parlay

slot gacor

kupu178 link alternatif

kupu178 slot

kupu178 daftar

kupu178 login

link daftar kupu178

judi bola

HOKI311

RATU311

link alternatif RATU311

Link daftar RATU311

link login RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

KUPU178

THOR311

KUPU178

KUPU178

KUPU178

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

THOR311

RATU311

KUPU178

KUPU178

HOKI311

THOR311

KUPU178

THOR311

THOR311

slot thailand

judi bola

THOR311

THOR311

KUPU178

THOR311

situs bola

THOR311

slot gacor

slot gacor

yakuza303

slot gacor

unobet77

slot gacor

slot gacor

RATU311

parlay

parlay

slot gacor

mix parlay

judi bola

judi bola

mix parlay

parlay

judi bola

sv388

judi bola

judi bola

judi bola

parlay

THOR311