Javascript Random Number Generator

Published: 28 December 2019
on channel: Coding Commanders
1,342
33

Create a vanilla JavaScript random number generator using the predefined JavaScript Functions:
1) Math.random
2) Math.floor
3) Math.ceil

#JavaScript #VanillaJavascript #VanillaJS

Take a look at the completed project here: https://www.codingcommanders.com/java...

JavaScript Random Number Generator Web Lesson:
https://www.codingcommanders.com/rand...

In this lesson, we build a vanilla JavaScript random number generator. The user enters a minimum and maximum value and our JavaScript will generate a pseudo-random integer within the given range.

We use the JavaScript pre-defined function Math.random() to generate a pseudo-random number. "Pseudo" means "not genuine" or "a sham".

Math.random uses an algorithm to simulate randomness. Because an algorithm is used, there is no way to produce actual randomness. Random means "chosen without method or conscious decision". The algorithm is the method used. If you know the algorithm, you can use it to predict results.

Don't get caught up on "pseudo". JavaScript, like other major programming languages, does a really good job of simulating randomness. It does so well, you can think of the results as a "random number".

Project File Structure

Project Folder: random-number-generator
index.html
random.css
chime.mp3

Math.floor() rounds a number down to the nearest integer.


Math.ceil() rounds a number up to the nearest integer.


HTML Tutorials: https://www.codingcommanders.com/html/

CSS Tutorials: https://www.codingcommanders.com/css/

Have fun using JavaScript to generate random numbers!


Watch video Javascript Random Number Generator online without registration, duration hours minute second in high quality. This video was added by user Coding Commanders 28 December 2019, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,342 once and liked it 33 people.