Generate numbers that divide evenly [closed]

2019-02-27 11:48发布

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;

标签: java math random
1条回答
欢心
2楼-- · 2019-02-27 12:31

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.

查看更多
登录 后发表回答