Quote:
Originally Posted by Old Pedant
You could also simply choose a random index value. It is then *possible* that a user will get the same image 2 times in a row, but the odds of that will only be 1 in N, where N is how many available images you have.
It's not perfect, but it's simpler and may work well enough.
|
Hey, I later on decided to do that ... its working as how I wanted, though I am getting some 0 when number is generated..
Code:
var index = Math.round(Math.random()*3);
if(index == 0)
{
index = Math.round(Math.random()*3);
}
function randomContent() {
var mainContent = document.getElementById("mainContent");
var randomImg="images/content" + index + ".png";
mainContent.src=randomImg;
}
window.onload = function() {
// Load Random Images
randomContent();
}
Go it working by changing to:
Code:
function randomContent() {
var index = Math.ceil(Math.random() * 3);
var mainContent = document.getElementById("mainContent");
var randomImg = "images/content" + index + ".png";
mainContent.src = randomImg;
}