Download

Issues with Random Array elements?

Somehow when I set my element in Get to a number, things work fine, but when I use random integer in range, it no longer works fine, and gives me the wrong array element. Is there anything wrong with getting random numbers in arrays that I am unaware of?

How can a random value be “wrong” ? Is it outside the range ?
If its a random element, you dont knwo beforehand what you gonna get. So how do you know its “wrong” ?

The problem seems to be with random integers in Range. They Dont work, it only works if I set one number in Get, but if I use the random integers in Range, the number that I get in the array willl be different to the random number.I know its wrong cause the chosen array element is highlighted and moves depending on the number and when its meant to go up for example, it goes left. Very, very strange…

However, when in the get array element, if I input a specific number instead, it works fine.

Exactly the same here! I have an array of 20 the same object, and try to throw them 1 by 1 randomly, then remove the chosen one from the array. If I use Random(0;Length-1), it moves an object that was already thrown, and in the end I finished with unmoved objects but an empty array.
If I repeat everything the same, but I always choose the 0 element, it works perfectly. Even works with for example 5 (but only 15 times of course). Here is my blueprint:

63b3ba54fabb9ac3f370c80c449389a39251ca01.png

I even tried “Remove index” instead of “Remove Item”, but it had the same result.

I found out what the issue was at the time. If you connect the random integer in range to different things, it will get random numbers for each place you want the random number. TL;DR - Create a variable and assign the random int to it. then use that variable everywhere you need that one random number. Hope it helps.

Yes, a local variable solved it, thanks! It was a bit strange for me, since I tried to use the random value at only one place. An “Exec” version of the random generator would be nice which only generates random number only once, then uses it until gets a command to generate another. (Like DoItOnce, until Reset)