Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate random between 0 - 9 but not 6 [closed]

What is the simplest way to generate a random number between 0 - 9 (inclusive both) excluding 6 in Javascript?

like image 764
Sawarnik Avatar asked Dec 24 '12 04:12

Sawarnik


2 Answers

Here is your one line solution :(

[0,1,2,3,4,5,7,8,9][Math.floor(Math.random()*9)]
like image 130
James Avatar answered Oct 05 '22 03:10

James


Generate a random number between 0 and 8 and then add 1 if it's >=6

like image 40
Eugene Osovetsky Avatar answered Oct 05 '22 03:10

Eugene Osovetsky