My JavaScript random number is always initialized to 1? -
Can anyone help me in troubleshooting this problem? In the code below, It does not make any sense! You can see that circus and
circy are being started appropriately, but
theta always starts with 1! Console log
theta = 1 every time I load the page.
var circx = Math.floor (Math.random (* * number.MAX_VALUE)% papwidth; Var circy = Math.floor (Math.random (* * Number MAX_VALUE)% papheight; / * Circus, Circuit: The initial position of the circle on the paparizer * / var mycirc = paper.circle (circuses, cerci, 10); mycirc.attr ("filling", "# f9c624"); var theta = math.flur (math .Rendum () * no.mx_avnaa% 4 + 1; / * theta = 1 <---> Object is going to 45-degree angle theory = 2 <---> Object Going on 135-degree angle theta = 3 <---> Object is going to 225 degree angle atta = 4 <---> Object It is growing at a 315 degree angle * / console.log ("theta =" + theta);
& gt; Math.random () * number. MX_Vision 8.365923028455995e + 307
E + 307 means that it ends in zero 307. Dubbles integer is not stored in exact, take that moded 4 and add 1 and you always get 1. (Or you do 99.99999 ...% of time).
Comments
Post a Comment