# Need help with "GetRandomInt"

**URL:** <https://forums.unrealengine.com/t/need-help-with-getrandomint/1412154>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, question, fortnite\
**Created:** [November 22, 2023, 4:01pm UTC](https://forums.unrealengine.com/t/need-help-with-getrandomint/1412154 "2023-11-22T16:01:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LyssaSugarNya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lyssasugarnya/32/722321_2.png) [@LyssaSugarNya](https://forums.unrealengine.com/u/LyssaSugarNya)\
**Post date:** [November 22, 2023, 4:01pm UTC](https://forums.unrealengine.com/t/need-help-with-getrandomint/1412154/1 "2023-11-22T16:01:23Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/c/3/fc34244841dc30721802dbebbef5ec002017cb81.png)

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/e/9/ce91de7768ec2ed595706b35ee2b2e1d5f30a677.png)

Shotty1 is a variable  
Button1 is an button\_device in the island

whenever `Button1` is pressed, It will add +1 for `Shotty1`. And the same happens with `Shotty2` when `button2` is pressed.

When the voting period ends, If `shotty1` is greater than shotty2 it grants a shotgun and it would grant a different shotgun if `shotty2` was greater.  
But what happens when they both are equal? that’s when I tried to use `GetRandomInt` to randomly choose between Shotty1 and Shotty2. Here is the screen shot:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/6/8/368a900f816540ff998b8df45b51142ee94eabe3.png)

BUT… the problem is… whenever the voting is calculated and weapons are being granted, Both Shotty1 and Shotty2 are granted. I have no idea why this happens and came to the conclusion that I’m using `GetRandomInt` wrong.

If anybody know why this is happening please let me know, I would appreciate any replies

---

<div class="post-metadata">

**Author:** ![GraemeBB](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/graemebb/32/1106150_2.png) [@GraemeBB](https://forums.unrealengine.com/u/GraemeBB)\
**Post date:** [November 22, 2023, 4:30pm UTC](https://forums.unrealengine.com/t/need-help-with-getrandomint/1412154/2 "2023-11-22T16:30:10Z")

</div>

Couple of rewrites:  
set Shotty1 +=1

and  
if(Shotty1 = Shotty2):  
rng:int = GetRandomInt(1,2)  
if(rng = 1):  
do a thing  
else:  
do a different thing

Then just make sure this isn’t being called twice, because I think it is.

---

<div class="post-metadata">

**Author:** ![LyssaSugarNya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lyssasugarnya/32/722321_2.png) [@LyssaSugarNya](https://forums.unrealengine.com/u/LyssaSugarNya)\
**Post date:** [November 22, 2023, 4:33pm UTC](https://forums.unrealengine.com/t/need-help-with-getrandomint/1412154/3 "2023-11-22T16:33:12Z")

</div>

Thank you, I appreciate your reply. I’ll make these changes and check if it’s working. I also think it’s running twice.

---

<div class="post-metadata">

**Author:** ![LyssaSugarNya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lyssasugarnya/32/722321_2.png) [@LyssaSugarNya](https://forums.unrealengine.com/u/LyssaSugarNya)\
**Post date:** [November 22, 2023, 4:53pm UTC](https://forums.unrealengine.com/t/need-help-with-getrandomint/1412154/4 "2023-11-22T16:53:22Z")

</div>

It works now, thanks to you. It was running twice because I overlooked something.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [December 22, 2023, 4:54pm UTC](https://forums.unrealengine.com/t/need-help-with-getrandomint/1412154/5 "2023-12-22T16:54:05Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
