GMS 2 Randomize position by multiples of 24

Nathan

Member
I have a very simple spawning object which randomly spawns an object every 2 seconds. What I would like it to do the spawner creates the objects in the same y position of the spawner, but the x position I want to be randomized multiples of 24 (ie. x, x+24, x+48, x+72, x, x-24, x-48, x-72 etc) so each object spawns in a different x position. How would I make a randomize like this? Thanks!
 

TheouAegis

Member
x + random_range(-72,72) div 24 * 24

Or

x + round(random(6) - 3) * 24

Or

x + irandom_range(-3,3)*24

Or

x + (irandom(6)-3)*24

Or

x + 24 * irandom(3) * choose(1,-1)

Or

x + 24 * choose(0,1,2,3) * choose(-1,1)

Or

x + 24 * choose(-3,-2,-1,0,1,2,3)

Or

x + choose(-72,-48,-24,0,24,48,72)

Or

x + sin(random(pi*2)) * 72 div 24 * 24
 

TheouAegis

Member
The pi formula i think might yield 0 more frequently as well. At least the *choose(-1,1) methods yield 8 outcomes. The Power of Twos!

I know it wasn't obvious to everybody, but I was just throwing out random crap to make a point. LOL
 

Nathan

Member
Oh awesome! I didn't know they added that functionality! Much appreciated :)
Actually I'm using a mac laptop with a touch pad so I don't have a middle click haha Any idea what the alternative way to make that happen might be?
 
Top