Generate Random Image using Javascript

The following code snippet shows how to generate Random Image using Javascript.

//Paste the code into script tag
var picutes=["picture1","picture2",picture3"];


//Paste the code into image tag

src=\"+pictures[Math.floor(Math.random()*10)]+".gif\" width=\"105\" height=\"100\" />");


Author: Phagu Mahato04 Feb 2014 Member Level: Gold   Points : 6

Thank for Posting article in Random Image using Javascript . You can also use this code snippet for it


SCRIPT language=JavaScript(Starting Script)
function swapImage() {
theImages = new Array("Myimage1.jpg", "Myimage2.jpg", "Myimage3.jpg");
whichImage = Math.floor(Math.random()*theImages.length);
/SCRIPT(Close script)



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: