View Single Post
Old 12-05-2012, 08:34 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by devnull69 View Post
Be careful
Code:
Math.floor(Math.random()*36);
will never have the value "36". Math.random() will result in values between 0 and 1, including 0 but excluding(!) 1. So you will have to use
Code:
Math.floor(Math.random()*37);
Ummm...but roulette *ALSO* has a "00" spot (at least on American roulette wheels). So thare are actually 38 spots.

But of course "00" and "0" are the same number, when viewed as a number. So I'd simply make the random number be -1 to 36. And then -1 means "00".

Code:
var ball = Math.floor( Math.random() * 38 ) - 1;
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote