# Random image from array

**URL:** <https://forum.kirupa.com/t/random-image-from-array/248494>\
**Category:** flash\
**Created:** [January 8, 2008, 8:37pm UTC](https://forum.kirupa.com/t/random-image-from-array/248494 "2008-01-08T20:37:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rocketrud](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@Rocketrud](https://forum.kirupa.com/u/Rocketrud)\
**Post date:** [January 8, 2008, 8:37pm UTC](https://forum.kirupa.com/t/random-image-from-array/248494/1 "2008-01-08T20:37:33Z")

</div>

The following code works but I would like it to be modified so that the same image never shows twice.

var pics:Array = new Array();  
pics[0] = “text/theatre1.jpg”;  
pics[1] = “text/theatre2.jpg”;  
pics[2] = “text/theatre3.jpg”;  
pics[3] = “text/theatre4.jpg”;  
function showRandomPic() {  
var n:Number = Math.ceil(Math.random()\*pics.length-1); //create random number  
pic\_mc.loadMovie(pics[n]); // load associated image from random number  
}  
showRandomPic();

Could somebody please modifiy this and repost it so that it won’t chose the same pic twice.

Thanks in advance
