10 examples of 'random number 1-36' in JavaScript

Every line of 'random number 1-36' 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
this disclaimer
294export function randomNumber(lessThan = 52) {
295 const seed = Math.random();
296 return parseInt(seed * lessThan);
297}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

6function randomNumber() {
7 return parseInt(Math.random() * 100, 10);
8}
68function randomNumber(boundary) {
69 return parseInt(Math.random() * boundary);
70 //return Math.floor(Math.random() * boundary);
71}
26function random() {
27 return Math.random().toString(36).substr(2);
28}
14function RandomHexDigit(allow_zero) {
15 const chars = allow_zero ? '0123456789ABCDEF' : '123456789ABCDEF';
16 return chars.charAt(Math.floor(Math.random() * chars.length));
17}
4function randomNumber() {
5 return Math.floor(Math.random()*100)
6}
664function random11() {
665
666 return random(-1, 1, true);
667
668}
34export function generateNumber(min,max){
35 if(min==null)
36 min=Number.MIN_SAFE_INTEGER
37 if(max==null)
38 max=Number.MAX_SAFE_INTEGER
39 return ((Math.random() * (max - min) ) + min).toString();
40}
104function random2() {
105 return (Math.random() * 2) | 0;
106}
51function random (n){
52 if(typeof n === 'object'){
53 var times = n[1]-n[0];
54 var offset = n[0];
55 return Math.random()*times + offset;
56 }else{
57 return n;
58 }
59}

Related snippets