Posted By

d55beck on 06/25/10


Tagged

javascript random simple


Versions (?)

Very Simple Random Image


 / Published in: JavaScript
 

Extremely simple random image when using similar naming structure and a set number of images (eg. imagePrefix1,jpg, imagePrefix2,jpg, etc.)

  1. <script type="text/javascript">
  2. var randomnumber = Math.floor(Math.random()*4)+1; // Start at 1 instead of 0
  3. document.write('<img src="imagePrefix_' + randomnumber + '.jpg" />');
  4. </script>

Report this snippet  

You need to login to post a comment.