# Randomize a chance of dead

**URL:** <https://forums.unrealengine.com/t/randomize-a-chance-of-dead/473518>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [October 26, 2020, 4:53pm UTC](https://forums.unrealengine.com/t/randomize-a-chance-of-dead/473518 "2020-10-26T16:53:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cybeaster](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cybeaster](https://forums.unrealengine.com/u/Cybeaster)\
**Post date:** [October 26, 2020, 4:53pm UTC](https://forums.unrealengine.com/t/randomize-a-chance-of-dead/473518/1 "2020-10-26T16:53:04Z")

</div>

I have a task to create a chance of actor dead. The chance have to be depending from the value I set manually.  
So is there a function in UE4 that can take a value in percentages, and make an event to be happened depending on the value?

---

<div class="post-metadata">

**Author:** ![King\_Crazy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@King\_Crazy](https://forums.unrealengine.com/u/King_Crazy)\
**Post date:** [October 26, 2020, 5:09pm UTC](https://forums.unrealengine.com/t/randomize-a-chance-of-dead/473518/2 "2020-10-26T17:09:47Z")

</div>

One thing you could do is use `FMath::FRand()` to get a float between 0.0 and 1.0 (think of it as 0% and 100%), and then check if that value is less than the percent you’re checking for (which should also be between 0.0 and 1.0. Think of 0.5 as 50%).

So an example would be: You want the chance of an actor dying to be 20%.

```
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float chanceForDeathPercent = 0.2f;

```

(Making that a UPROPERTY will allow you to edit it in Blueprints, if you need to)

Then, when you’re checking to see if the actor is dead, you could do something like this:

```
const float deathRoll = FMath::FRand();
if (deathRoll < chanceForDeathPercent)
{
    // Set the actor as dead
}

```

(You could also do this with integers using 0 to 100 and `FMath::RandRange()`)

Now, I don’t believe this is _statistically_ accurate (That is, it might not _actually_ happen 20% of the time). I’m sure someone who took statistics class could tell you why this might be slightly off. However, as far as game mechanics go, it should be fine.
