Get 3 different integer from a random int combined with data table row names

Hi everyone!

I have a widget called handler with a horizontal box, I can populate this box with 3 other widgets, the problem is that when I randomly choose these 3 widgets sometimes 2 or 3 of them appear the same and I would like to avoid this happening to me.

This is my function for the random int, but it doesn’t remove the duplicates, does anyone have an idea how I could solve it?

Thank you.

Shuffle the array and grab the first 3. No need to remove anything.

• the function terminates early, the loop never loops

• be mindful of pure function evaluation, the script generates 2 different random values since the node is accessed twice

Thanks for the reply! I had no idea that the shuffle node existed, I tried to do some tests, and although it seems simple I can’t do it.

I would like to make a small correction to the image I shared, it was a screenshot of modified function so I don’t use the for loop inside the function due its doing nothing (at least it seems) but I use for loop on event pre construct of a menu, so the nodes I’m currently using are composed as follows:

On pre construct i have something like this

And the function (pure or not) was like this:

Even using shuffle instead of random doesn’t change much, furthermore I find it difficult to understand how to take only 3 names from shuffle if it doesn’t have an integrated output node.

So what exactly are you trying to do? Run a function once and have it return 3 non-repeating Data Table entries?

Yes, exactly :smiley:

1 Like

We generate 3 entries :point_up_2:, and use the return value to operate on them :point_down: :

image


Alternatively:


But it’s generally more convenient to have functions do 1 thing. One generates data, the other populates something with the generated data. Handy when things grow in scope, and they always do.

Thank you!!!

I had been trying for days, but without an exact logic I would have continued to wander endlessly.

You deserve the crown you wear!

1 Like