# Please spot the flaw in my logic (random integer in range)

**URL:** <https://forums.unrealengine.com/t/please-spot-the-flaw-in-my-logic-random-integer-in-range/427907>\
**Category:** Blueprint\
**Tags:** error, logic, random-numbers, unreal-engine, Blueprint, question\
**Created:** [June 22, 2018, 12:24pm UTC](https://forums.unrealengine.com/t/please-spot-the-flaw-in-my-logic-random-integer-in-range/427907 "2018-06-22T12:24:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![llll\_Sabre\_llll](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@llll\_Sabre\_llll](https://forums.unrealengine.com/u/llll_Sabre_llll)\
**Post date:** [June 22, 2018, 12:24pm UTC](https://forums.unrealengine.com/t/please-spot-the-flaw-in-my-logic-random-integer-in-range/427907/1 "2018-06-22T12:24:55Z")

</div>

Hi all,

Have I made an glaring error here? Surely it should never hit the print string?  
I’ve been staring at this too long so perhaps I can no longer see the obvious!

 ![245089-unusuallogic.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/d/1/0d1c2e21579ce02e522bb42b9ba2a8d77a22676c.jpeg)

Thanks,  
Sabre.

---

<div class="post-metadata">

**Author:** ![Mosel3y](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mosel3y](https://forums.unrealengine.com/u/Mosel3y)\
**Post date:** [June 22, 2018, 12:48pm UTC](https://forums.unrealengine.com/t/please-spot-the-flaw-in-my-logic-random-integer-in-range/427907/2 "2018-06-22T12:48:32Z")

</div>

Every time you’re checking that variable it’s generating a new random integer. So it’s a different number at every branch. Meaning it could be 0, 1, 2 at the last branch.

You should promote the result of Random Integer in Range to a local variable before the first branch. And then compare that variable, instead of the output of the random node.

---

<div class="post-metadata">

**Author:** ![llll\_Sabre\_llll](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@llll\_Sabre\_llll](https://forums.unrealengine.com/u/llll_Sabre_llll)\
**Post date:** [June 22, 2018, 2:13pm UTC](https://forums.unrealengine.com/t/please-spot-the-flaw-in-my-logic-random-integer-in-range/427907/3 "2018-06-22T14:13:18Z")

</div>

Solved. Thanks Mosel3y!  
I had a feeling it was something I should have spotted!
