Random items from array

Hi everyone!
I have an array of 17 items created with get all actors from class.
Now I need randomly pick 9 items without repeat, someone can help me?

Hi @anonymous_user_f69d806b

you can shuffle an array to make the order of the elements random, and pick only the first 9
OR
you can create an array of numbers ,0,1,2,3,…up to 17
now if you shuffle this array you will end up with a random order.
for example the index0 could be 4 index1 11…
so you call the first 9 index of this array —> to call 9 randomly elements in your array

3 Likes

Also you can use “For each loop with break” where the break will happen (and stop further iterations) once it reached Index 9

Or

For Loop and then specify number of iterations, use the array’s Get(a copy) with index from the loop

Or stick to @Est_engine’s advice ;]

thank you, yes i use shuffle and “foreachloopwithbreak”, now it’s working :slightly_smiling_face:

1 Like