Generating a Random Number in JavaScript in range 0 to 9
function
randomString() {
var
chars = "0123456789";
var
string_length = 1;
var
randomstring = '';
for
(var i = 0; i < string_length; i++) {
var
rnum = Math.floor(Math.random() * chars.length);
randomstring +=
chars.substring(rnum, rnum + 1);
}
alert(randomstring); //alert will show the random number
}
//setInterval call randomString() function in every 2 second
SB = setInterval(function() { randomString(); }, 2000);
No comments:
Post a Comment