Webwork
/
Random Images on Reload



To randomize the images either reload the page or click here.

Head:
<script language="javascript">
random.m=714025; random.a=4096; random.c=150889;
random.seed = (new Date()).getTime()%random.m;
function random()
{
random.seed = (random.seed*random.a + random.c) % random.m;
return random.seed / random.m;
}

function randomizeimages()
{
randomizeimage('image1', 6, '', '.jpg');
randomizeimage('image2', 6, '', '.jpg');
randomizeimage('image3', 6, '', '.jpg');
randomizeimage('image4', 6, '', '.jpg');
randomizeimage('image5', 6, '', '.jpg');
randomizeimage('image6', 6, '', '.jpg');
}

function randomizeimage(img, count, base, type)
{
document.images[img].src = base + Math.floor(random() * count + 1) + type
}
</script>

Body:
<body onload="randomizeimages()">

<img src="1.jpg" height="150" name="image1"> <img src="1.jpg" height="150" name="image2"> <img src="1.jpg" height="150" name="image3"> <img src="1.jpg" height="150" name="image4"> <img src="1.jpg" height="150" name="image5"> <img src="1.jpg" height="150" name="image6">

<p style="text-align: center">To randomize the images either reload the page or <a href="javascript:;" onClick="randomizeimages()">click here</a>.</p>
Previous | Webwork Table of Contents | Next >