Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
Hi,

I want to generate random numbers in js from specific set of numbers iteratively e.g:

generate random numbers from array of (2,3,4) excluding 1 and next time from (1,3,4) excluding 2 like that. I have used Math.floor and Math.random()but they generate the numbers from given range like(1 to 4). What if i want to exclude any number or want to generate number from given specific set of numbers??
Posted 29-Dec-12 22:46pm
aeman466
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

var randomnumber=Math.floor(Math.random()*11)
  Permalink  
Comments
aeman at 30-Dec-12 6:01am
   
can u please elaborate how does it work??
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this
 
Math.floor((Math.random()*10000)+1);
 

Thanks
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 245
1 OriginalGriff 210
2 Manfred R. Bihy 190
3 CHill60 180
4 _Amy 155
0 OriginalGriff 7,445
1 Sergey Alexandrovich Kryukov 6,157
2 Maciej Los 3,774
3 Peter Leow 3,448
4 CHill60 2,702


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100