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

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:

Thank you for reading.

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

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.

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.

1 Like

There you go.

Thanks again.

1 Like

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

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:

1 Like

reroute nodes. Just search for them.

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.