- You set
a
to a random number between0
and5
. - You set
b
to a random number between0
and5 - a
- You set
c
to a random number between0
and5 - a - b
- You set
d
to5 - a - b - c
As a result, you get 4 numbers with a sum of 5.
So as not to be boring and repeat tons of questions on Stack Overflow about finding a number in a given range, which would be a sub-task there, here’s a link: How do I generate random integers within a specific range in Java?
1
solved How to hand out a number randomly between variables in Java? [closed]