Check out example codes for "math.random". It will help you in understanding the concepts better.

Code Example 1

``````function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}``````

Code Example 2

``````function randomNumber(min, max) {
return Math.random() * (max - min) + min;
}``````

Code Example 3

``````function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive
}``````

Code Example 4

``````//To genereate a number between 0-1
Math.random();
//To generate a number that is a whole number rounded down
Math.floor(Math.random())
/*To generate a number that is a whole number rounded down between
1 and 10 */
Math.floor(Math.random() * 10) + 1 //the + 1 makes it so its not 0.``````

Code Example 5

``````function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}``````

Code Example 6

``````<script>
function randomNum(min,max){
var number = Math.random(min,max)
document.getElementById("text").innerHTML = number;
};
</script>
<button onclick="randomNum(0,10)"></button>
<p id=text></p>
<!-- must add </p>, or <div id=text ></div>, this code will set
<p id=text></p> to a random number through 0-10 ex: 7-->``````

Learn ReactJs, React Native from akashmittal.com