# Random Mc based on Array?

**URL:** <https://forum.kirupa.com/t/random-mc-based-on-array/149062>\
**Category:** flash\
**Created:** [May 25, 2005, 6:33pm UTC](https://forum.kirupa.com/t/random-mc-based-on-array/149062 "2005-05-25T18:33:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yossarian](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@yossarian](https://forum.kirupa.com/u/yossarian)\
**Post date:** [May 25, 2005, 6:33pm UTC](https://forum.kirupa.com/t/random-mc-based-on-array/149062/1 "2005-05-25T18:33:39Z")

</div>

I’m trying to create a basic app where you shoot MCs moving at random. That part works but I’m not sure how I can call an Array at random instead of keeping to the basic shape I’m using now, would be fun with a bit of difference…

Any idea how I could achieve that usig the below code?

```auto
var i;
// get sound
var gunfire = new Sound();
gunfire.attachSound("gunfire");
_root.hit1.onPress = function() {
	gunfire.start();
	i++;
	
	_root.bull.duplicateMovieClip("bulletNew", i);
	if (i == 10) {
		i = 0;
	}
	// hit test on target
	if (_root.target_mc.hitTest(_root._xmouse, _root._ymouse, false)) {
		_root.gun.gotoAndPlay(2);
		_root.target_mc._x = 0;
		_root.target_mc._y = random(300);
		_root["bulletNew"+x].removeMovieClip(); 
	}
};
// initialise stuff
_root.onLoad = function() {
	// hide the mouse
	Mouse.hide();
};
//loop
_root.onEnterFrame = function() {
	//put cross hairs to mouse coords
	_root.gun._x = _root._xmouse;
	_root.gun._y = _root._ymouse;
	// target move
	_root.target_mc._x += 10;
	if (_root.target_mc._x<0 || _root.target_mc._x>Stage.width) {
		_root.target_mc._x = 0;
		_root.target_mc._y = random(300);
	}
	
};

```

Appreciate any kind suggestions!!!

Yossi
