JavaScript makes it really easy to generate and use pseudo-random numbers. By using the built-in Math.random() function, you are able to achieve just that.
Math.random() will give you a random floating point number from 0 to 1 (non-inclusive of 1) and so to convert that result into a whole number, you'll need to implement some basic math.
In this video I show you a simple example of how to generate a random number and also how to generate a random whole number (or integer) between a range of 1 and X.
For your reference, check this out:
[ Ссылка ]
Support me on Patreon:
[ Ссылка ]
Follow me on Twitter @dcode!
If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
#dcode #javascript #webdev
How to Generate Random Numbers in JavaScript - Math.random
Теги
codecodingprogrammingtutorialintroductionbeginnerwalkthroughguidesoftwaredevelopmentsimpleeasyintoenglishwithexampleexamplesjsjavascriptes5es6es7ecmascriptecmascript2015ecmascript2016ecmascript2017htmlhtml5csscss3websitewebwholenumbersdatatypeintegerintegerspseudorandomnessMathobjectarraymethodfunctiongeneratecreatemakeseeduniformdistributionscalerangeMath.floorMath.randomroundingroundfloorceilMath.ceilfloatingpointfloating-point