# Randomly generating from an array?

**URL:** <https://forum.kirupa.com/t/randomly-generating-from-an-array/205030>\
**Category:** Uncategorized\
**Created:** [October 25, 2006, 3:21pm UTC](https://forum.kirupa.com/t/randomly-generating-from-an-array/205030 "2006-10-25T15:21:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![regen](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@regen](https://forum.kirupa.com/u/regen)\
**Post date:** [October 25, 2006, 3:21pm UTC](https://forum.kirupa.com/t/randomly-generating-from-an-array/205030/1 "2006-10-25T15:21:13Z")

</div>

hey just wondered if i could get a bit of help/pointers:

basically i have a list of 17 movie clips that i need to be randomly selected and placed on the stage for a pinball esq game, i already have the gravity code that will effect these movie clips but im at a bit of a loss how to A) randomly select them B) get them to appear on the stage.

help please?

---

<div class="post-metadata">

**Author:** ![SacrificialLamb](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@SacrificialLamb](https://forum.kirupa.com/u/SacrificialLamb)\
**Post date:** [October 25, 2006, 8:15pm UTC](https://forum.kirupa.com/t/randomly-generating-from-an-array/205030/2 "2006-10-25T20:15:17Z")

</div>

first you sould put them in an array. if you named them like (thein1, thing2 thing3) you don’t need to do this but an array is more flexazbile

```auto
theng_array = [name1, thing, bit, bob]

```

then you’ll need a for loop to place them

```auto

for (var i:Number = 0; i<theng_array.length; i++) {
tempName = theng_array*
tempName._x = random(Stage.width-20)+10
tempName._y = random(Stage.height-20)+10
}

```

i used random(Stage.width-20)+10 to find a place on Stage that is 10 away from all sides
