I need to generate three random numbers that sum to equal another number n generated by an equation.
im writting this program in java but im not the strongest at maths and i cant figure it out
int n = 10; //Generated total
int n1 = n * object1.frequency;
int n2 = n * object2.frequency;
int n3 = n * object3.frequency;
im using the randomly generated numbers to generate a list of objects consisting of the 3 types. ive tried this approach assigning each object a frequency such as 0.3 and the sum of all three object's frequency total one. the problem is this method produces a double and even if i round it. it can either generate less or more than i want(n)
Aucun commentaire:
Enregistrer un commentaire