JavaScript RNG
JavaScript RNG
var n = Math.random(); /* you can use math method as a value in a variable because it's generating a
random number between 0-1.
This math random method will give you a 16 decimal place number and the number between 0-0.9
to 16 decimal places, it autimaticly give a number between 0-1 but never reaches 1*/
n = n * 6; /*we multiply the n value here, that's how we scale the random number, so the decimal
number that will sho up will be around 0-5.9 but never reches 6
and the result will get the math method automaticly, and the result will be decimal and it's because
the math random method will always give a random number with 16 decimal places*/
//so, if you want to have a rounds number you just need to use math floor method:
n = Math.floor(n);
//now if you want to make a dice here, you can use the math random method:
var dice = Math.floor(Math.random()*6 + 1); /*the dice never showing up a 0 right? so you have to
add 1 to get a number between 1-6.
id you didn't add the 1 the random generator will be giving a number from 0-5.99 and not giving a 6.
so if you add 1
the 0 will be 1 and the 5.99 will be 6.99, after that you can just use the math floor method so you
didn't get a decimal number*/
/*dice = Math.floor(dice);*/ //you can actually just put this floor method to the variable value and
input the math random method inside and also add 1.
console.log(dice);
//Now as an exercise we'll make a random love generator with rpompt and alert:
console.log(lovePercentage);