programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Mathrandom every x

Greenhorn
Posts: 5
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,

Paweł Baczyński
Bartender
Posts: 2087
44
If you need a random multiple of 17 then get a random integer in a correct range and multiply it by 17. Simple.

Greenhorn
Posts: 5
Paweł Baczyński wrote:If you need a random multiple of 17 then get a random integer in a correct range and multiply it by 17. Simple.

I don't understand, can you show how you mean?

Paweł Baczyński
Bartender
Posts: 2087
44
You said you want a random integer like 0, 17, 34, 51...
So, get a random integer like 0, 1 , 2, 3...
Multiply the value by 17 and you'll get 0, 17, 34, 51...

Greenhorn
Posts: 5
But, I have already multiplied with the highest number I want the x to be which is 408. And thats 17, 24 times.