# \[AS2\] Good method for random damage

**URL:** <https://forum.kirupa.com/t/as2-good-method-for-random-damage/325366>\
**Category:** programming\
**Created:** [October 11, 2011, 6:22pm UTC](https://forum.kirupa.com/t/as2-good-method-for-random-damage/325366 "2011-10-11T18:22:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![silverneo188](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@silverneo188](https://forum.kirupa.com/u/silverneo188)\
**Post date:** [October 11, 2011, 6:22pm UTC](https://forum.kirupa.com/t/as2-good-method-for-random-damage/325366/1 "2011-10-11T18:22:28Z")

</div>

What’s the best way to calculate random damage based on a power variable and enemy defense variable

So lets say these are the stats  
My Attack - 12  
Enemy Def - 4

What would be the best formula? I don’t want it to be inbetween 0 and another. This is the only formula I can get

```php

//The minimal damage
min_damage = playerAttack -= enemyDef;
randomDam = random(playerAttack);

if(randomDam < min_damage){
randomDam = min_damage
}

```

But this will return with 8 (the minium damage based on our variables) a lot since it is more likely to land below 8.

Something more like a random number between the minimum damage and the player’s attack
