Ok, so this is my problem. I'm wondering how I could randomly generate an amount of numbers while staying in a limit for the total of all of them. So say I have four variables. (2, 5, 2, 3 (This is what I would like it to look like.)) And they all are randomly generated and they can't go above a certain condition but they have to meet it. (Being 12 for this case.) My question is firstly how would you fairly generate these numbers without certain variables being oped in a sense. As in when its generating the first one it could for all we know make it nine and then there's only a total of 3 more you can add before the condition is reached.

The first variable would be oped to the other ones which I do not want. I still want it to be random but make it so that they're spread out somewhat. Because if it generated the numbers in order then each variable after another would become smaller and smaller before some would have to be zero in some cases. Then what else i'm wondering is how would you make it so when they are generated they DO reach the goal. Not just stay under it but reach it. Sorry if i'm making this sound confusing but i'm very tired atm.

But if anyone has any idea please leave a reply saying what you think I could do. Thank you!