Jul 24, 2002 #1 Sam63 Technical User Nov 19, 2001 18 US I am familar with using Math.random()... i.e. var i = Math.floor(1 + Math.random() * 10); but I'm not sure how to get a random number in a set of numbers i.e. 2, 4, 6, 8, 10 ....any suggestions. Sam
I am familar with using Math.random()... i.e. var i = Math.floor(1 + Math.random() * 10); but I'm not sure how to get a random number in a set of numbers i.e. 2, 4, 6, 8, 10 ....any suggestions. Sam
Jul 24, 2002 #2 jemminger Programmer Jun 25, 2001 3,453 US Sam63, if memory serves correctly, Math.Floor(Math.random() * x) will return a number between 0 and x. ====================================== if (!succeed) try(); -jeff Upvote 0 Downvote
Sam63, if memory serves correctly, Math.Floor(Math.random() * x) will return a number between 0 and x. ====================================== if (!succeed) try(); -jeff
Jul 24, 2002 Thread starter #3 Sam63 Technical User Nov 19, 2001 18 US I need to get a random number from a set of numbers that may not be consecutive, i.e. 6, 10, 14, 18 or 2, 4, 6, 8, 10 Math.floor(Math.random * x) does not do this. Any suggestions?? Upvote 0 Downvote
I need to get a random number from a set of numbers that may not be consecutive, i.e. 6, 10, 14, 18 or 2, 4, 6, 8, 10 Math.floor(Math.random * x) does not do this. Any suggestions??
Jul 24, 2002 #4 jemminger Programmer Jun 25, 2001 3,453 US hmm... set up an array to hold your set of numbers: var set = new Array('2','4','6','8','10'); then use Math.floor(Math.random * set.length); hope this works...I can't test it on the public computer I'm at right now... :-( ====================================== if (!succeed) try(); -jeff Upvote 0 Downvote
hmm... set up an array to hold your set of numbers: var set = new Array('2','4','6','8','10'); then use Math.floor(Math.random * set.length); hope this works...I can't test it on the public computer I'm at right now... :-( ====================================== if (!succeed) try(); -jeff