[Solved] Isn't this was supposed to work as a Random without repeating?

Here I am again!

Your random number should be in the range of 0 to the number of children in the variable minus one (because arrays starts at 0 you need to subtract 1 from the count)

See this similar example, I used sprite name instead of just numbers:

Edit: also, you need to move the remove variable at action down. It’s currently deleting the element before the value is read. So, it reads a different number. Get the value then delete the element.

1 Like

You mean this:

I’m not sure why you have a while event. The random number should be from 0 to the size of the array (number of children ) -1 since the 1st element is 0.

Here’s another example. It picks 4 numbers at a time. You wouldn’t need the repeat. I’m not at my PC or I would create something new.

The strategy is:
Create an array with the numbers you want picked. In this example, I set index to 1 and repeated it 10 times. So, the array had the numbers 1 thru 10. In this version, it automatically creates the array if there are no children. Sort of like shuffling cards when all are dealt.

To choose a number you pick a random number from 0 to the number of children in the array -1 because the array starts at (0)

You then pick the value in the array and then delete that element

It was so simple!

Thanks so much!

1 Like