# Need help, random function

**URL:** <https://forum.kirupa.com/t/need-help-random-function/242967>\
**Category:** Uncategorized\
**Created:** [November 1, 2007, 4:04am UTC](https://forum.kirupa.com/t/need-help-random-function/242967 "2007-11-01T04:04:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vin23leo](https://avatars.discourse-cdn.com/v4/letter/v/b77776/32.png) [@vin23leo](https://forum.kirupa.com/u/vin23leo)\
**Post date:** [November 1, 2007, 4:04am UTC](https://forum.kirupa.com/t/need-help-random-function/242967/1 "2007-11-01T04:04:32Z")

</div>

hey guys,

can anyone help me, atm i have a game where the user hits bees, now the bees have a random function, so they can move around:

//this code is on the bees itself  
acceleration = 5  
newpos = function () {  
ranx = Math.round((Math.random ()\*200));  
rany = Math.round ((Math.random ()\*200));  
}  
newpos();  
this.onEnterFrame = function() {  
this.\_x += ((ranx-this.\_x)/acceleration);  
this.\_y += ((rany-this.\_y)/acceleration);  
if (Math.round(this.\_x) == ranx || Math.round(this.\_y) == rany) {  
newpos();  
}  
};

now i have it so when they get hit, the acceleration = 30. the bees get dizzy.

after you hit it again it will splat, i want to make the bees come towards the screen, so they can splat on the screen, in the users face. can anyone help me, much appreciated

cheers
