I have an array of 7 strings, and i want to pick 5 of them that are all different from each other. How can i achieve that? I tried using for loop and while but i can’t figure it out. Even shuffle doesn’t seem to work.
You just need to shuffle, and then loop from 1 to 5. What is not working out? ![]()
I’d also add a contains test before adding to the result array. If the result array already contains the shuffled number, then shuffle until it’s unique.
Just because it’s random doesn’t mean that in 5 tries you can’t get a duplicate, unless you would work on a copy of the array and remove the random element each shuffle.
Sorry but i really cannot figure it out, where am i wrong?
So i’ll explain how i see this. I make an array, then shuffle it. After that i start a for loop from 0 to 4, and set a new array with a get connected to the index in order to get them in their respective index order after shuffle. Then i “convert it to an array?”, and add that to the new array. The final print is testing purposes, and obviously im wrong in this example because it’s not working. I think the problem is the get, which doesn’t seem to do exactly what i want, but i can’t seem to find any other node that works better.
Make the array and put it in a variable. The way have it here, you’re making a array every time you pick anything from it ![]()
So i need to add 1 variable per array pick?
Make array → variable → shuffle → everything else ![]()
At the moment, every time around the loop, this line gets called
and ‘make array’ is called.
That’s why you need to put the output of make array into a variable. Then just use the variable.
Correct ![]()
In the loop use the variable you’ve made. Do the get from the variable.
I understand what youre saying but i want to save the picks in a new array
I want to pick from the array of 7 elements, 5 random elements that are unique and add them to a new array
It works for you? ![]()
Yes, thanks!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.






