# Random Number inside a Loop

**URL:** <https://forum.kirupa.com/t/random-number-inside-a-loop/317513>\
**Category:** flash\
**Created:** [December 23, 2010, 5:17am UTC](https://forum.kirupa.com/t/random-number-inside-a-loop/317513 "2010-12-23T05:17:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfx1026](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jfx1026/32/2943_2.png) [@jfx1026](https://forum.kirupa.com/u/jfx1026)\
**Post date:** [December 23, 2010, 5:17am UTC](https://forum.kirupa.com/t/random-number-inside-a-loop/317513/1 "2010-12-23T05:17:47Z")

</div>

I’m trying to generate 5 random numbers within a range. I’m saving these inside an array through the use of a for loop.

```auto

for ( var j:int = 0; j < (questions); j++) {
    var randomNum:Number = Math.floor(Math.random()*(1+MAX_number-MIN_number))+MIN_number;
    var answerNumbers:Array = new Array();
    answerNumbers[j] = (randomNum);
}

```

The result of this is that the 5th slot has a number. The first 4 are “undefined”. Why would the last loop work and the others fail?
