Random Integer

Hi all,

I want a box to spawn on 3 random locations. for this i created an arry with (0, -100, 100). this is my x locaiton. y and z are just 0. Now i use random integer to generate a number and use this as the spawning x value. but sometimes or most of the times, the number is repeating immediately. like the previous int and current int are same. so the box spawns on the same location twice or more, which i dont want to happen at all. thorough out my level i want this spawning to happen. so this incident should keep looping. thats y i am using random integer . its the only one that keeps on generating a value. Let me know if there is any other option to do this. I tried loop, but since its only 3 items. loop didnt work for me. i dont know if i am doing it wrong . Thanks in advance for the Suggestion.

Best to show the code.

You can’t stop random ints being the same. Something you can do, is make an array with ints, and shuffle it. Then, any coords you pull from the array, have to be unique :slight_smile:

1 Like

i mean, for eg it generates as 0,-100,-100,100,-100… here the problem is with the 3rd int. which is same as its precedor. i want a gate to check this and ignore the repeating item. and keep the flow with immediately non repeating items. So my box keeps spawing everytime for a new location from the list of array. otherwiese they keep overlapping on the same location. i tried coding this but the logic and methods i tried didnt made sense at all.

You either have to make a list of valid random locations, put them in an array, and shuffle the array.

Or write some to code to check you haven’t used the location before. The array is much easier.

1 Like

Try one of the next macros:


It checks for duplicate values and re-calls the randomizer.


It selects random unique array elements.

My Products

1 Like

Thanks for the code. I will check it out.

Thank you for the Code. it worked!!! :grinning: