Random but not repeat using array

Hi I just learn Gdevelop and I have some trouble making random pop up 1 digit number… i’m trying to find more simple way by using array but doesnt work well

so I want to make random number show up in range between 1 to 5 but not repeated. and after all number done, its start (reset) random 1 to 5 again.

help please

Hey there welcome to GDevelop!

The easiest way I could think of is to use array variables. Since you only have 5 numbers, then you can add the arrays in the scene variables page.

You’ll be using / modifying the “array”, and the “array_copy” will be used to reset the numbers.

The event is not very complicated. I’ll try to explain it.

1- choose a random index between 0 and the number of children in the array - 1.
(the reason for -1 is because the first child index starts at 0 and not 1)
2- set the text to the value of the child variable with the random index.
3- remove this child variable from the array.
4- check if “array” is empty, then reset it by copying the “array_copy”.

1 Like

Another way is to add the Array Tools extension to the project, and use the functions it provides:


and as @insein wrote in step 4, reset with a copy of the default array once some_array has 0 children.