# How to shuffle a specific number of elements in an array?

So, l have an array of integers and I want to get N shuffled integers from it.
I also want to store those values in different variables.

For example, let’s say that the given array is {1,2,3,4,5,6,7,8,9}. I want the program to get 4 random integers from it and store them to RandomNumber1, RandomNumber2, RandomNumber3, RandomNumber4.

Is it possible? I’m kind of a beginner and my english is not that good, so I hope that I can understand any of your answers. Thank you Unfortunately Array.getChildCount() is broken currently, so you’ll have to hard code the number of children, but let’s say that it’s 10 and your array is called RandomNumbers.
// First try to select 4 random positions
RandPos1 = Random(10)
RandPos2 = Random(10)
RandPos3 = Random(10)
RandPos4 = Random(10)

// Now do a bunch of loops to ensure that you picked four different positions
While
OR
RandPos2 == RandPos1
THEN => RandPos2 = Random(10)

While
OR
RandPos3 == RandPos1
RandPos3 == RandPos2
=> RandPos3 = Random(10)

While
OR
RandPos4 == RandPos1
RandPos4 == RandPos2
RandPos4 == RandPos3
=> RandPos4 = Random(10)

// Now assign the values from those positions
RandomNumber1 = RandomNumbers[RandPos1]
RandomNumber2 = RandomNumbers[RandPos2]
RandomNumber3 = RandomNumbers[RandPos3]
RandomNumber4 = RandomNumbers[RandPos4]

It’s cumbersome to write CONDITIONAL and ACTION a bunch of times, so I hope you can understand my shorthand above.

1 Like

Can you elaborate? I’ve used this with arrays without any issues, and it’d be good to understand where it’s shortfalls are.

1 Like

Should be fixed in next release.

1 Like

Ahh, that only applies to an instance/object array variable. Not a scene variable, which is what I’ve been using.

1 Like