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.
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.
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.
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.
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.