Create 3 RandomNumber without the same twice

Hello there :slight_smile: ,

I’m facing an issue and i would like some help please.

I’m generating a RandomInRange number 3 time, the problem is that sometimes the RandomInRange generate the same number 2 or 3 times in a row thus i can have 2 or 3 cars at the same position and that’s not what i want. I’m stuck thinking how i can solved this problem (which I think is easy) but i do not know how to do.

Did you have any idea to put me on the right path ?
Thank you.

Use this because if u use (0,3)it will pick 0,1,2,3 one of the four numbers if it picks the same number again just use

Change variable “VariableName” +(ADD) 1

That way it will add 1 so it will be 1 then 2 and then 3

Idk why your using the random thingy though

You would need a while loop, on top of your 3 creating objects events.
While spawn_id equals a previous value, set spawn_id to RandomInRange(1,3).

The problem is to record previous values. You can record them in a variable like: value to avoid.1, value to avoid.2, etc.
Sometimes I use a “memory” text variable where I add little by little the values I want to avoid. (e.g. add “;2;” ) And the while loop is going on till the “;” +VariableString(spawn_id)+";" can be found in the memory variable, with a search in text condition.

BTW, if you want a number among 1,2 and 3, you need RandomInRange(1,3).

Thanks for you answer
You right i will use 1+Random(3) it’s much easier and i think try the while condition.

Put the 3 numbers into an array. Then select a random array position from 0 to array child count, get the value at that random position and remove the entry from the array. This will ensure you get each number occurring once, and randomly.


I am kind of confused. You are three times in a row spawning a car in one frame, due to the repeat 3 times, in one of 3 random places, due to your random variable, and do not want to spawn more than two at the same place. That would mean you just want each 3 actions to be called once in the repeat 3 times, so all you want to do is to execute all object creation actions at once, without any other fancy event or condition or did I missunderstand something?