# Randomly upload images

**URL:** https://forum.kirupa.com/t/randomly-upload-images/253301
**Category:** Uncategorized
**Created:** [February 28, 2008, 10:41pm UTC](https://forum.kirupa.com/t/randomly-upload-images/253301 "2008-02-28T22:41:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Sean\_Murray](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Sean\_Murray](https://forum.kirupa.com/u/Sean_Murray)
#### Post date: [February 28, 2008, 10:41pm UTC](https://forum.kirupa.com/t/randomly-upload-images/253301/1 "2008-02-28T22:41:09Z")

</div>

I am wondering if someone can help me.  
I have some actionscript which is designed to randomly load 6 of 18 possible .jpg images into a flash file. The script currently does randomly choose an image six different times, but often the same image will be chosen twice. I need to ensure that if an image is already chosen that it will not be chosen a second time. I am pasting the script that I have below. If you can help me I would be extremely grateful.

newN = 0;

lastN = 0;

function randRange(min:Number, max:Number):Number {

```
        var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;

        return randomNum;

```

}

function getANumber():Number {

```
        x = randRange(0, 18);

        return x;

```

}

function getAnImageIndexNumber () {

```
        while (newN == lastN) {

                    newN = getANumber();

        }

        lastN = newN;

        return newN;

```

}

n = getAnImageIndexNumber();  
if(n == lastN){

```
        if (n &lt; 17){
                    n = n + 1;
        }else{
                    n = n – 1;
        }

```

}

debug = true;

\_root.onLoad = function(){

```
images_xml = new XML();
images_xml.ignoreWhite=true;
images_xml.onLoad = parse;

if (debug) {
    images_xml.load("images.xml");
} else {
    images_xml.load("/logos/images.aspx" + "?cachebuster=" + new Date().getTime());
}

```

};

function startLoading1(whichImage) {  
loadMovie(whichImage, “imageLoader1”);  
}

function startLoading2(whichImage) {  
loadMovie(whichImage, “imageLoader2”);  
}

function startLoading3(whichImage) {  
loadMovie(whichImage, “imageLoader3”);  
}

function startLoading4(whichImage) {  
loadMovie(whichImage, “imageLoader4”);  
}

function startLoading5(whichImage) {  
loadMovie(whichImage, “imageLoader5”);  
}

function startLoading6(whichImage) {  
loadMovie(whichImage, “imageLoader6”);  
}

function parse(success) {  
if (success) {  
imageArray = new Array();  
var root = this.firstChild;  
var imageNode = root.lastChild;  
var s=0;  
while (imageNode.nodeName != null) {  
imageData = new Object;  
if (debug) {  
imageData.path = imageNode.attributes.path;  
} else {  
imageData.path = imageNode.attributes.path + “?cachebuster=” + new Date().getTime();  
}  
imageArray[s]=imageData;  
imageNode = imageNode.previousSibling;  
s++;  
}  
imageArray.reverse();  
trace(imageArray.length);  
n = getAnImageIndexNumber();  
startLoading1(imageArray[n].path);  
n = getAnImageIndexNumber();  
startLoading2(imageArray[n].path);  
n = getAnImageIndexNumber();  
startLoading3(imageArray[n].path);  
n = getAnImageIndexNumber();  
startLoading4(imageArray[n].path);  
n = getAnImageIndexNumber();  
startLoading5(imageArray[n].path);  
n = getAnImageIndexNumber();  
startLoading6(imageArray[n].path);  
} else {  
trace(‘problem’);  
}  
}
