# AS3 Random Array Problem

**URL:** <https://forum.kirupa.com/t/as3-random-array-problem/301057>\
**Category:** flash\
**Created:** [December 3, 2009, 1:12am UTC](https://forum.kirupa.com/t/as3-random-array-problem/301057 "2009-12-03T01:12:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MBugsy](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@MBugsy](https://forum.kirupa.com/u/MBugsy)\
**Post date:** [December 3, 2009, 1:12am UTC](https://forum.kirupa.com/t/as3-random-array-problem/301057/1 "2009-12-03T01:12:05Z")

</div>

I’m a flash noob and I’m having trouble randomizing few dynamically loaded swf files.

1. I have a UILoader on the stage with an instance name of bg\_ldr. It is working properly.

2. I have (attempted) to set up a function called getRandomNumber (see code below) and I believe it is correct.

3. BUT… specifically I don’t know what I should put in this part of the code: bg\_ldr.source = bgArray[???]; and I think this area is the problem. I thought I could just call my function, like this:

bg\_ldr.source = bgArray[getRandomNumber];

But it’s not working. Any help you could give would be very much appreciated, and thanks in advance for your trouble!

```auto
var bgArray:Array = ["TheWhimbrel.swf", "DesertSun.swf", "DohaCityScape2.swf", "DohaNights.swf", "FindingTheWay.swf", "JourneyOfFive.swf", "PaleolithicDoha.swf", "Sandstorm.swf","SedimentalSouls.swf","TheLeader.swf","CranesOfLight.swf"];
var loadimage:String = bgArray[getRandomNumber(0,bgArray.length - 1)];

function getRandomNumber(min:Number, max:Number):Number
{
	var randomNumber:Number = Math.round(Math.random() * (max - min) + min);
	return randomNumber;
}

bg_ldr.source = bgArray[getRandomNumber];

```
