# Random

**URL:** https://forum.kirupa.com/t/random/14547
**Category:** Uncategorized
**Created:** [February 27, 2003, 5:47pm UTC](https://forum.kirupa.com/t/random/14547 "2003-02-27T17:47:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![geestring](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@geestring](https://forum.kirupa.com/u/geestring)
#### Post date: [February 27, 2003, 5:47pm UTC](https://forum.kirupa.com/t/random/14547/1 "2003-02-27T17:47:04Z")

</div>

i want balls to go around randomly, i got that. but how do i make them go all the way to the specified border instead of stopping in the middle.

---

<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 27, 2003, 9:57pm UTC](https://forum.kirupa.com/t/random/14547/2 "2003-02-27T21:57:35Z")

</div>

if(ball.\_x \< rightborder )  
{  
ball.\_x keep moving right  
}else{  
ball.\_x stop moving  
}  
???

if you post your AS, we can help you a lil more…

---

<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 28, 2003, 7:25pm UTC](https://forum.kirupa.com/t/random/14547/3 "2003-02-28T19:25:46Z")

</div>

function getdistance(x, y, x1, y1) {  
var run, rise;  
run = x1-x;  
rise = y1-y;  
return (\_root.hyp(run, rise));  
}  
function hyp(a, b) {  
return (Math.sqrt(a_a+b_b));  
}  
MovieClip.prototype.reset = function() {  
//specify the width and height of the movie  
width = 550;  
height = 400;  
//-------------------  
var dist, norm;  
this.x = this.\_x;  
this.y = this.\_y;  
this.speed = Math.random()\*4+60  
;  
this.targx = Math.random()\*width;  
this.targy = Math.random()\*height;  
dist = \_root.getdistance(this.x, this.y, this.targx, this.targy);  
norm = this.speed/dist;  
this.diffx = (this.targx-this.x)\*norm;  
this.diffy = (this.targy-this.y)\*norm;  
};  
MovieClip.prototype.move = function() {  
if (\_root.getdistance(this.x, this.y, this.targx, this.targy)\>this.speed) {  
this.x += this.diffx;  
this.y += this.diffy;  
} else {  
this.x = this.targx;  
this.y = this.targy;  
if (!this.t) {  
this.t = getTimer();  
}  
if (getTimer()-this.t\>1) {  
this.reset();  
this.t = 0;  
}  
}  
this.\_x = this.x;  
this.\_y = this.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 28, 2003, 7:34pm UTC](https://forum.kirupa.com/t/random/14547/4 "2003-02-28T19:34:28Z")

</div>

how do i use this piece of code?
