10 examples of 'random number generator 4 digits' in JavaScript

Every line of 'random number generator 4 digits' 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
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}
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

14function RandomHexDigit(allow_zero) {
15 const chars = allow_zero ? '0123456789ABCDEF' : '123456789ABCDEF';
16 return chars.charAt(Math.floor(Math.random() * chars.length));
17}
43function randomNumber(len) {
44 const buf = [],
45 chars = '0123456789',
46 charLen = chars.length;
47
48 for (let i = 0; i < len; ++i) {
49 buf.push(chars[getRandomInt(0, charLen - 1)]);
50 }
51
52 return buf.join('');
53}
88private rndInt(min: number, max: number): number {
89 return Math.floor(Math.random() * (max - min + 1) + min);
90}
8function randomNumber(min, max) {
9 return Math.floor(Math.random() * (max - min + 1)) + min;
10}
20function rndI(n) {
21 return parseInt(rnd(n));
22}
294export function randomNumber(lessThan = 52) {
295 const seed = Math.random();
296 return parseInt(seed * lessThan);
297}
6function randomNumber() {
7 return parseInt(Math.random() * 100, 10);
8}
4function randomNumber(min, max) {
5 return Math.random() * (max - min) + min;
6}
82function randomNumber(min, max) {
83 return Math.random() * (max - min) + min;
84}

Related snippets