# Array values mysteriously change

**URL:** <https://forum.kirupa.com/t/array-values-mysteriously-change/269750>\
**Category:** flash\
**Created:** [September 1, 2008, 3:03am UTC](https://forum.kirupa.com/t/array-values-mysteriously-change/269750 "2008-09-01T03:03:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vurx](https://avatars.discourse-cdn.com/v4/letter/v/e99b99/32.png) [@vurx](https://forum.kirupa.com/u/vurx)\
**Post date:** [September 1, 2008, 3:03am UTC](https://forum.kirupa.com/t/array-values-mysteriously-change/269750/1 "2008-09-01T03:03:25Z")

</div>

the code below is a much simplified version but it duplicates the mysterious error. below i trace the contents of genesArray using a function and all of the cells are different, but when i trace it again they are all the same. i am truly baffled as to why.

```auto

package {
    import flash.display.MovieClip;
    
    public class GMachine extends MovieClip{

        private var randomArray:Array;
        private var total:int;
        private var rndm:int;
        private var genesArray:Array;

        
        public function GMachine(){
            randomArray = new Array();
            genesArray = new Array();
            total = 5;
            makeGenes();
        }
        private function randomArrayGenerator():Array{
                for(var i:int = 0; i < total; i++){
                    rndm = Math.random()*10;
                    randomArray* = rndm;
                }
            return randomArray;
        }
        
        private function makeGenes():void{
            trace("here they are different");
            for(var i:int = 0; i < total; i++){
                genesArray* = randomArrayGenerator();
                traceArray(genesArray*);
            }
            trace("why are these the same?");
            for(i = 0; i < total; i++){
                traceArray(genesArray*);
            }
        }

        private function traceArray(inArray:Array):void{
            var tmpStr:String = "";
                for(var j:int = 0; j < inArray.length; j++){
                    tmpStr+=inArray[j]+" ";
                }
            trace(tmpStr);
        }

    }
}

```

sample output:

```auto

here they are different
9 0 2 6 5 
6 1 0 5 9 
7 4 1 1 7 
3 3 0 6 0 
0 9 7 4 6 
why are these the same?
0 9 7 4 6 
0 9 7 4 6 
0 9 7 4 6 
0 9 7 4 6 
0 9 7 4 6

```
