# Random Damage delt (Game AS2) - Question

**URL:** <https://forum.kirupa.com/t/random-damage-delt-game-as2-question/327939>\
**Category:** flash\
**Created:** [April 6, 2012, 3:09pm UTC](https://forum.kirupa.com/t/random-damage-delt-game-as2-question/327939 "2012-04-06T15:09:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MAGG0T](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@MAGG0T](https://forum.kirupa.com/u/MAGG0T)\
**Post date:** [April 6, 2012, 3:09pm UTC](https://forum.kirupa.com/t/random-damage-delt-game-as2-question/327939/1 "2012-04-06T15:09:36Z")

</div>

Im trying to add a random damage is delt when the Enemy attacks here is the code i have

```auto
onClipEvent (load)
{
    
    var scale = this._xscale;
}
onClipEvent (enterFrame)
{
    var distance = 150;
    var tx = this._x;
    var ty = this._y;
    var sx = _root.content.window.hero._x;
    var sy = _root.content.window.hero._y;
    if (Math.sqrt((sx - tx) * (sx - tx) + (sy - ty) * (sy - ty)) < distance)
    {
        if (tx < sx)
        {
            this.gotoAndStop(3);
            this._xscale = scale;
        } // end if
        if (tx > sx)
        {
            this.gotoAndStop(3);
            this._xscale = -scale;
        } // end if
    } // end if
    if (Math.sqrt((sx - tx) * (sx - tx) + (sy - ty) * (sy - ty)) > distance)
    {
        _root.content.window.enemy.gotoAndStop(1);
    } // end if
    if((_currentframe==3)and(this.hitTest(_root.content.window.hero))) {
_root.content.window.hp.health--

    } // end if
   
}

```

As you can see \_root.content.window.hp.health-- is only dealing -1 per hit the enemy makes Lets say i want the damage to be random and between 5-10 how would i do this?  
Thanks in advance!
