0% found this document useful (0 votes)
12 views1 page

Generate Random Numbers with Math.random

The document explains how to use Math.random() to generate random numbers, providing a default range of 0 to 1. It demonstrates how to adjust the range to 0 to 20 by multiplying the result by 20 and adding 1. Additionally, it introduces Math.trunc() to convert floating-point numbers into whole integers.

Uploaded by

patelsurlko20
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Generate Random Numbers with Math.random

The document explains how to use Math.random() to generate random numbers, providing a default range of 0 to 1. It demonstrates how to adjust the range to 0 to 20 by multiplying the result by 20 and adding 1. Additionally, it introduces Math.trunc() to convert floating-point numbers into whole integers.

Uploaded by

patelsurlko20
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Math.

random: For random generate a number() by default it gives in 0 to 1 decimal


number . If you want 0 to 20 write like this
[Link]() * 20)+1; it gives you 0 to 20 decimal number
[Link](): It gives you whole number convert floot number into int
example: -
[Link]([Link]() * 20)+1);

You might also like