Do something randomly in game time to time (like scratching)

Use Set Timer and plug a random float into it.

Then use conditionals such as “Is player in range” to determine whether another set timer is scheduled after the last executes.

I am wondering how can i make enemy AI to do random things? I need to make my wondering AI to scratch and moan randomly. Where shouls i put the code (blueprint). I have tried to put code in Character blueprint and in TICK event i created random int between 0 and 50 in every tick. Then if number is 0 it plays animation. It kinda works, mut there is fails there also.

If i go near NPC the behavior tree starts to take over and NPC walks towards me, it should not play the animation anymore but it will. Also when the npc is near me it still plays animation randomly because tick never ends. Is there a better way to do what i am trying to do? Should i use interface to pass boolean values between blueprints or how should i go on?