2
votes

how to make random numbers between 4 numbers ?

for example, i have a stage { 550x400 } in center of stage i have object {50x50} and i am creating new objects, but i don't need to create new objects on my static object in center of stage. so i need to set random position between 4 numbers - [0,250 ; 300,550] for x and [0,175 ; 225,400] for x

tempNewEnemy._x = getRandom(0,250 ; 300,550)
tempNewEnemy._y = getRandom(0,175 ; 225,400)

is it possible to do this, or i can do it in other ways ?

1

1 Answers

2
votes

Since the ranges are the same, how about generating two random numbers? One for the range (0-250 along x) and (0-175) along y) then another random number that sets it to the left or to the right of your static object?

Maybe something like:

tempNewEnemy._x = Math.round(Math.random() * 250) + ((Math.random() < 0.5) ? 0 : 300);
tempNewEnemy._y = Math.round(Math.random() * 175) + ((Math.random() < 0.5) ? 0 : 225);