In many cases, random numbers are required, so we have provided some specific instructions for use. In many cases, random numbers are required. Here are some specific instructions for use.
Js random number base
1. javascript random number function Math. random ()
Random (Math. random Method)
Public static random (): Number
Returns a pseudo-random number n, where 0 <=n <1. The returned number is called "pseudo-random" because it is calculated technically in a confidential manner.
Return
Number: a Number.
Generate random numbers within a specified range
The Math. random () method has no parameters. 0 ~ is returned ~ Random number between 1. If 0 ~ is to be generated ~ Random between n
Number, which can be in the following format:
Math. floor (Math. random () * n)
To generate m ~ Random Number between n, which can be used:
Math. floor (Math. random () * n) + m
Javascript random number advanced application
① Since JavaScript was generated, many browsers have built-in random number generation methods. For example:
Var number = Math. random ();
This method generates a floating point number between 0 and 1.
② Based on Time, random numbers can also be generated. For example:
Var now = new Date ();
Var number = now. getSeconds ();
This generates an integer ranging from 0 to 59 based on the current time.
Var now = new Date ();
Var number = now. getSeconds () % 43;
This generates an integer ranging from 0 to 42 based on the current time.
③ Here we will introduce a fairly good random number generator program, which can be applied in many fields.