Gustav Andersson

Greenhorn

Posts: 5

posted 11 months ago

Hello!

I need some help. I am trying to make a object change x coordinate everytime it falls down to a y coordinate and then it should start over on the top but with a new x coordinate.

For this im using math.random(). But I want it to randomly be picked with x = 17.

At the moment im using = x = (int)(Math.random()*408) and 408 is end of the frame.

So to summarize it, like this (x can only be 17, 34, 51 etc):

x = 0

x = 17

x = 34

x = 51

And this want I to be in random order, like this for example:

x = 17

x = 0

x = 51

x = 34

It was pretty hard to explain, but how you understand.

Sincerely,

I need some help. I am trying to make a object change x coordinate everytime it falls down to a y coordinate and then it should start over on the top but with a new x coordinate.

For this im using math.random(). But I want it to randomly be picked with x = 17.

At the moment im using = x = (int)(Math.random()*408) and 408 is end of the frame.

So to summarize it, like this (x can only be 17, 34, 51 etc):

x = 0

x = 17

x = 34

x = 51

And this want I to be in random order, like this for example:

x = 17

x = 0

x = 51

x = 34

It was pretty hard to explain, but how you understand.

Sincerely,

Gustav Andersson

Greenhorn

Posts: 5

Gustav Andersson

Greenhorn

Posts: 5

Campbell Ritchie

Marshal

Posts: 56598

172

posted 11 months ago

Stop using Math#random for arithmetic. Create an instance of Random and use one of its methods. You will find more discussion here. As you have already been told, then simply multiply the result by 17.

Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |