10 examples of 'math.floor(math.random()' in JavaScript

Every line of 'math.floor(math.random()' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
21export function randomInt(min, max){
22 return Math.ceil( min - 0.5 + (Math.random() * max));
23}
8function randomInt () {
9 return Math.round(Math.random() * 255)
10}
46function randomInt(max) {
47 return Math.ceil(Math.random() * max)
48}
5static randomInt() {
6 return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
7}
55function getrand(min, max){
56 return Math.floor(Math.random()*(max-min+1)+min);
57}
82export function randomInt(min, max) {
83 min = Math.ceil(min)
84 max = Math.floor(max)
85 return Math.floor(Math.random() * (max - min)) + min
86}
66function randomInt (min,max) { return Math.floor(Math.random() * (max - min + 1) + min); }
358function randomInt(min, max) {
359 return Math.floor(Math.random() * (max - min + 1) + min);
360}
110function randomInt(min, max) {
111 if (!min) {
112 min = RAND_MIN;
113 }
114
115 if (!max) {
116 max = RAND_MAX;
117 }
118
119 return Math.floor(min + (1 + max - min) * Math.random());
120}
15export function getRandomInt(min = 0, max = 100) {
16 min = Math.ceil(min);
17 max = Math.floor(max);
18 return Math.floor(Math.random() * (max - min + 1)) + min;
19}

Related snippets