The random function of JS
1.math.random (); The result is a random number between 0-1 (including 0, excluding 1)
2.math.floor (num); Parameter num is a numeric value, and the function result is the integer portion of Num.
3.math.round (num); The parameter num is a numeric value, and the function result is the integer rounded by Num.
Math: A Mathematical object that provides a mathematical calculation of the data.
Math.random (); Returns a random number between 0 and 1 (including 0, excluding 1).
Math.ceil (n); Returns the smallest integer greater than or equal to N.
With Math.ceil (Math.random () *10), the probability of taking 0 is minimal when the random integer 1 to 10 is obtained.
Math.Round (n); Returns the value of the integer after n rounding.
With Math.Round (Math.random ()), a random integer of 0 to 1 can be obtained evenly.
With Math.Round (Math.random () *10), a random integer of 0 to 10 is obtained in a basic equilibrium, with half the probability of obtaining a minimum value of 0 and a maximum of 10.
Math.floor (n); Returns the largest integer less than or equal to N.
With Math.floor (Math.random () *10), a random integer of 0 to 9 can be obtained evenly.
JavaScript random function is Math.random ()
<script type= "Text/javascript" >
document.write (Math.random ());
</script>
The output is 0-1 of 16 decimal digits
You can use this decimal size to make a lot of judgments.
Such as:
<script type= "Text/javascript"
document.write ("decimal number generated by JavaScript random function is ")
var Javascript = Math.random ();
var javascriptr = parseint (javascript*10);
var JAVASCRIPTL = parseint (javascript*100);
document.write (Javascript);
document.write ("<br><br>javascript 0-9 of integers generated by random functions is ")
document.write ( JAVASCRIPTR);
document.write ("<br><br>javascript 0-99 of integers generated by random functions is ")
document.write ( JAVASCRIPTL);
if (javascriptr>=5) {
document.write ("<br><br>" +javascriptr+ ">=5");
}else{
document.write ("<br><br>" +javascriptr+ "<5");
}
if ( JAVASCRIPTL>=50) {
document.write ("<br><br>" +javascriptl+ ">=50");
}else{
document.write ("<br><br>" +javascriptl+ "<50");
}
</script>
<script language= "JavaScript"
bg = new Array (3);
Bg[0] = ' 1 '
bg[1] = ' 2 '
bg[2] = ' 3 '
index = Math.floor (Math.random () * bg.length);
document.write ("& Lt Body background= "+bg[index]+" .jpg> ");
</script>