# How do I get 4 different random integers from a range?

**URL:** <https://forums.unrealengine.com/t/how-do-i-get-4-different-random-integers-from-a-range/377352>\
**Category:** Blueprint\
**Tags:** random-numbers, integer, unreal-engine, Blueprint, question\
**Created:** [November 24, 2016, 10:16pm UTC](https://forums.unrealengine.com/t/how-do-i-get-4-different-random-integers-from-a-range/377352 "2016-11-24T22:16:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_1786a85d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1786a85d](https://forums.unrealengine.com/u/anonymous_user_1786a85d)\
**Post date:** [November 24, 2016, 10:16pm UTC](https://forums.unrealengine.com/t/how-do-i-get-4-different-random-integers-from-a-range/377352/1 "2016-11-24T22:16:33Z")

</div>

Hello,  
I’ve been trying to solve this question for quite a while now: how would I get 4 different random integers from a range.

I have a range that four integers need to be picked out of: 0-24. These four integers can’t be the same, because these integers in the long run tell where an actor needs to be spawned (and they shouldn’t spawn in the same place). How would I accomplish something like this? Please note that this system also needs to work with 3, 5 and 6 different integers as well.

Here’s my current setup:

 ![116268-untitled.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/8/3/b83ef90a1f4750d5011f7e6f735797bae3ce4633.png)

Thank you for reading.

---

<div class="post-metadata">

**Author:** ![NoobsDeSroobs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NoobsDeSroobs](https://forums.unrealengine.com/u/NoobsDeSroobs)\
**Post date:** [November 24, 2016, 11:17pm UTC](https://forums.unrealengine.com/t/how-do-i-get-4-different-random-integers-from-a-range/377352/2 "2016-11-24T23:17:01Z")

</div>

Just make a random number in that range and add it to an array. Then create another random int and check if it is already inside the array. If not add it. Keep going until the array has four ints in it.

HTH

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1786a85d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1786a85d](https://forums.unrealengine.com/u/anonymous_user_1786a85d)\
**Post date:** [November 25, 2016, 12:38am UTC](https://forums.unrealengine.com/t/how-do-i-get-4-different-random-integers-from-a-range/377352/3 "2016-11-25T00:38:29Z")

</div>

Hi, thanks for replying!  
Could I see how you accomplished this? When I try it, it creates an infinite loop. I’m not super experienced at UE4, as you can tell, sorry for the inconvenience.

Thanks.

---

<div class="post-metadata">

**Author:** ![NoobsDeSroobs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NoobsDeSroobs](https://forums.unrealengine.com/u/NoobsDeSroobs)\
**Post date:** [November 25, 2016, 3:57am UTC](https://forums.unrealengine.com/t/how-do-i-get-4-different-random-integers-from-a-range/377352/4 "2016-11-25T03:57:42Z")

</div>

I have never done it, but make a loop and check the size of the array every loop. If it is \> than 4, just exit. Use “branch”. Once you have tried, post an image of what you have and I can tell you what you are doing wrong.

Remember you can make a loop by connecting the exec pin of the node where you add the new random int to the node that checks the size of the array.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1786a85d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1786a85d](https://forums.unrealengine.com/u/anonymous_user_1786a85d)\
**Post date:** [November 25, 2016, 4:34am UTC](https://forums.unrealengine.com/t/how-do-i-get-4-different-random-integers-from-a-range/377352/5 "2016-11-25T04:34:32Z")

</div>

![116301-untitled.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/b/1/db181051948aff921af6f03ef15f08cd243be3ff.png)

There you go.

Thanks again.

---

<div class="post-metadata">

**Author:** ![NoobsDeSroobs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NoobsDeSroobs](https://forums.unrealengine.com/u/NoobsDeSroobs)\
**Post date:** [November 25, 2016, 4:47am UTC](https://forums.unrealengine.com/t/how-do-i-get-4-different-random-integers-from-a-range/377352/6 "2016-11-25T04:47:08Z")

</div>

First off, check if the length is \< 4 just in case you change something so it adds 2 at once. If the array is larger than 4 it will run forever.

Next, dont connect the output of the get random int node to your add node. That makes a new int. One that you didnt check.

[http://puu.sh/stFoM/c29e0e66e2.png](http://puu.sh/stFoM/c29e0e66e2.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1786a85d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1786a85d](https://forums.unrealengine.com/u/anonymous_user_1786a85d)\
**Post date:** [November 25, 2016, 5:21am UTC](https://forums.unrealengine.com/t/how-do-i-get-4-different-random-integers-from-a-range/377352/7 "2016-11-25T05:21:29Z")

</div>

That worked perfectly. Thanks. By the way, how do you control the way the execution curves look? Is it a plugin?

Final output on my end:

 ![116303-untitled.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/b/3/fb3d7918e12ceb0e9c0a14a325f7eaedf40a6de4.png)

---

<div class="post-metadata">

**Author:** ![NoobsDeSroobs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NoobsDeSroobs](https://forums.unrealengine.com/u/NoobsDeSroobs)\
**Post date:** [November 25, 2016, 5:22am UTC](https://forums.unrealengine.com/t/how-do-i-get-4-different-random-integers-from-a-range/377352/8 "2016-11-25T05:22:36Z")

</div>

reroute nodes. Just search for them.

---

<div class="post-metadata">

**Author:** ![Deygus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deygus/32/982675_2.png) [@Deygus](https://forums.unrealengine.com/u/Deygus)\
**Post date:** [October 19, 2017, 11:32pm UTC](https://forums.unrealengine.com/t/how-do-i-get-4-different-random-integers-from-a-range/377352/9 "2017-10-19T23:32:54Z")

</div>

I know this is old but I am kinda looking to do something similar to control the randomized order of 3 books I am trying to spawn to ensure that 1 of them is always included except after trying this it didnt seem to work for me or I am using it wrong I guess.
