I want to make a random ad generator and I want it to generate a random number, and make someting like a select case in VB and put that html code into the browser
Printable View
I want to make a random ad generator and I want it to generate a random number, and make someting like a select case in VB and put that html code into the browser
Use Math.random()
isnt that just 0 and a 1 randomized?
Try this:
function doRandom(){
var intRand = Math.round((Math.random() * 2));
switch(intRand){
case 1:
alert("1");
break;
case 2:
alert("2");
break;
}//end switch
}//end function
Just multiply the upper range of the number that you want. If you want a number from 0 to 6 then use Math.random()*6. You have to round the number because Math.random() returns a number between 0.0 and 1.0 .
Chris
Yeah.
x = minimum number;
y = maximum number;
randNum = (x + Math.random() * y)
So, (1 + Math.random() * 100) would generate a number between 1 and 100.