Generate numbers that divide evenly [closed]

2019-02-27 11:47发布

问题:

I was wondering if there was an easy way to generate 2 numbers and make sure that one is evenly divisible by the other.

This is what i have so far:

Random rand = new Random();
int  d = rand.nextInt(90)*2 + 1;
int dd = rand.nextInt(d)+1;

回答1:

If you want to generate two numbers a and b where a divides b I.e. there exists an int k where a*k =b you can randomly generate a and then randomly generate k and multiply the two to get b.



标签: java math random