10 examples of 'random number between 1-9' in JavaScript

Every line of 'random number between 1-9' 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
162function random999(){
163 let a = Math.ceil(Math.random()*1000);
164 if(a>99){
165 return a;
166 }else{
167 if(a>9){
168 return '0'+a;
169 }else{
170 return '00'+a;
171 }
172 }
173}
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

8function randomNumber(min, max) {
9 return Math.floor(Math.random() * (max - min + 1)) + min;
10}
576function between(randNumMin, randNumMax)
577{
578 var randInt = Math.floor((Math.random() * ((randNumMax + 1) - randNumMin)) + randNumMin);
579
580 return randInt;
581}
24export function randomNumberInRange(min, max) {
25 return Math.random() * (max - min) + min;
26};
13export function random (max) {
14 return seeded.integerInRange(0, max)
15}
87function randNum (max) {
88 return faker.random.number({min: 1, max: max || 5})
89}
82function randomNumber(min, max) {
83 return Math.random() * (max - min) + min;
84}
4function randomNumber(min, max) {
5 return Math.random() * (max - min) + min;
6}
2function randomNumber(max, min) {
3 return Math.floor(Math.random() * (max - min + 1) + min);
4}
31number(min, max) {
32 const number = this.generate()
33 return Math.round((max - min) * number + min)
34}

Related snippets