How do you create exceptions to a math.random parameter?

My game has a function that spawns scooters at the left side of the screen, at random y coordinates, that then zip to the right side of the screen. The code is below. This works great, except for when two scooters happen to wind up with the same y coordinate. It’s difficult to explain, but I have a “leveling” function that stacks each scooter based on their y coordinate. When two scooters share the same y coordinate, they “flicker” when passing through each other. This is what I want to avoid. I want to make it so that the random y coordinate generated by my spawn function never duplicates itself (at least until the scooter with that specific y coordinate has removed itself). I hope I’m explaining myself well enough here. Any help would be much appreciated.

Thank you in advance,
Steven

local randTime = math.random( 500, 10000 ) function scooterFunction() local scooter = display.newImage("scooter.png") scooter.x = -100 scooter.y = math.random(1,1024) transition.to(scooter, {time = math.random(3000,6000), delay = 500, x = scooter.x + 968, onComplete=function() scooter :removeSelf() end})end timer.performWithDelay(randTime, scooterFunction, 0)[/code] [import]uid: 79394 topic_id: 26038 reply_id: 326038[/import]

I think there’s a few ways you could go about this but one of the easier ways to do this would be to alternate between a random between 1, 512 an 513, 1024.

This may or may not work for what you have in mind but if so it would ensure they didn’t get the same y coord.

Let me know if this helps :slight_smile:

Peach [import]uid: 52491 topic_id: 26038 reply_id: 105422[/import]