# I need some help with random placement in a boundary

**URL:** <https://forum.kirupa.com/t/i-need-some-help-with-random-placement-in-a-boundary/12970>\
**Category:** flash\
**Created:** [February 6, 2003, 9:39pm UTC](https://forum.kirupa.com/t/i-need-some-help-with-random-placement-in-a-boundary/12970 "2003-02-06T21:39:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrzimm](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@mrzimm](https://forum.kirupa.com/u/mrzimm)\
**Post date:** [February 6, 2003, 9:39pm UTC](https://forum.kirupa.com/t/i-need-some-help-with-random-placement-in-a-boundary/12970/1 "2003-02-06T21:39:03Z")

</div>

hi. I’m using the following code… and having problems with the random feature. I need to randomly place objects in an area could u give me a hand?

right now this code uses the stage to set the area. I don’t want to do that. I have started to put in a xmin and xmax but the random(); only likes one number … can some one please help me please…

z

my email address is [mrzimm@rogers.com](mailto:mrzimm@rogers.com) thanks for your time.

stop();

xMin = 65;  
xMax = 390;  
yMin = 65;  
yMax = 390;

//Number of balloons to be created  
totalBalloons = 5;  
//Set the dimensions of the screen so that we can randomly place the balloons  
screenWidth = 100;  
screenHeight = 100;  
//Create and place the balloon instances on the stage  
for (var i = 0; i\<totalBalloons; ++i) {  
var name = “balloon”+i;  
\_root.attachMovie(“balloon”, name, i);  
//var x = random (xMin, xMax); was just playing here.  
var x = random(screenWidth);  
var y = random(screenHeight);  
\_root[name].\_x = x;  
\_root[name].\_y = y;  
}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2003, 10:12pm UTC](https://forum.kirupa.com/t/i-need-some-help-with-random-placement-in-a-boundary/12970/2 "2003-02-06T22:12:01Z")

</div>

Wow… I tried your code and I got an error… then I looked at it and it seemed a bit off.

Try this…

```php
totalBalloons = 5;
screenWidth = 100;
screenHeight = 100;
for (i=0; i<totalBalloons; i++) {
	_root.attachMovie("balloon", "balloon"+i, i);
	myBalloon = _root["balloon"+i];
	x = random(screenWidth);
	y = random(screenHeight);
	myBalloon._x = x;
	myBalloon._y = y;
}

```
