Home > Web Front-end > JS Tutorial > body text

Summary of usage of random, round, ceil, floor of Math in js_javascript skills

WBOY
Release: 2016-05-16 17:07:04
Original
1453 people have browsed it

1.Math.random(); The result is a random number between 0-1 (including 0, excluding 1)
Math.random(); The result is a random number between 0-1 (including 0, excluding 1) [html] view plaincopyprint?


2.Math.floor(num); The parameter num is a numerical value, and the function result is the integer part of num (returns the largest integer less than or equal to n).


Math.floor(num); The parameter num is a numerical value, and the function result is the integer part of num (returns the largest integer less than or equal to n). [html] view plaincopyprint?


3.Math.round(num); The parameter num is a numerical value, The function result is the integer after num is rounded.


Math.round(num); The parameter num is a numerical value, and the function result is the integer after num is rounded. [html] view plaincopyprint?


4.Math.ceil(n); Returns the smallest value greater than or equal to n integer.


Math.ceil(n); Returns the smallest integer greater than or equal to n. [html] view plaincopyprint?


5.Math.ceil(Math.random()*10); When , it mainly obtains random integers from 1 to 10, and the probability of obtaining 0 is extremely small.


Math.ceil(Math.random()*10); mainly obtains random integers from 1 to 10, and the probability of obtaining 0 is extremely small. [html] view plaincopyprint?


6.Math.round(Math.random());Can be balanced Get a random integer from 0 to 1.


Math.round(Math.random()); can obtain random integers from 0 to 1 evenly. [html] view plaincopyprint?


7.Math.round(Math.random()*10); When , random integers from 0 to 10 can be obtained in a basically balanced manner, with the probability of obtaining the minimum value 0 and the maximum value 10 being less than half.


Math.round(Math.random()*10);, random integers from 0 to 10 can be obtained in a basically balanced manner, and the probability of obtaining the minimum value 0 and the maximum value 10 is less than half. [html] view plaincopyprint?


8.Math.floor(Math.random()*10); When , random integers from 0 to 9 can be obtained evenly.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template