javascript - simple random generator doesn't randomize correct -
i have created number generator ... yes generate random numbers... generator works fine every time reload page , press button give me random number.
lets generator give me number 289578 when press button first time. if reload page. give me random number 803175.
if press button, without reloading page give me number 803176 after gives me number 803177 once more give me number 803178.. if reload page give me number 8031771 reload , press button again give me number 80317711.
so instead of giving output on 6 different numbers start adding 1 until reload page , start adding 1000000. without randomize numbers.
any ideas ? want keep javascript.. please no jquery comments.
code:
var id = math.floor((math.random()*1000000)+1); document.getelementbyid("add-new").addeventlistener("click", function() { id += 1; });
your not doing randomness inside click handler, add 1.
maybe want just
document.getelementbyid("add-new").addeventlistener("click", function(){ id = math.floor((math.random()*1000000)+1); });
Comments
Post a Comment