Webwork
/
Multiple Image Randomizer

Another JavaScript randomization example, this one randomizes three separate image groups—tops, middles, bottoms—each of which has three separate photo options.

Web page:


To randomize the images 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', 3, 'tops/', '.png');
randomizeimage('image2', 3, 'middles/', '.png');
randomizeimage('image3', 3, 'bottoms/', '.png');
}

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

Body:

<div>
<img name="image1" src="tops/1.png" width="400" height="125" border="0"><br />
<img name="image2" src="middles/1.png" width="400" height="199" border="0"><br />
<img name="image3" src="bottoms/3.png" width="400" height="148" border="0"></div>
<p style="text-align: center">To randomize the images <a href="javascript:;" onClick="randomizeimages()">click here</a>.</p>

The photographs used in this demonstration are by Martin Schoeller. To view more of his work, check out:

Smithsonian/National Portrait Gallery

The New Yorker Portraiture Now Slide Show

Mediastorm Close-Up

Previous | Webwork Table of Contents | Next >