Generate numbers that divide evenly

java math random

798 просмотра

1 ответ

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;
Автор: user3020346 Источник Размещён: 13.11.2019 11:33

Ответы (1)

5 плюса


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.

Автор: Anthony Porter Размещён: 27.11.2013 05:45
Вопросы из категории :