Place the formula in cell A6 and stretch it to cell A155
=IF(COUNTIF($A$5:A5;15)>=ROUNDUP($B$2*150/100);-10;
IF(COUNTIF($A$5:A5;-10)>=(150-ROUNDUP($B$2*150/100));15;
IF(RAND()<$B$2/100;15;-10)))
Each press of F9 or Ctrl+Shit+F9 (like any other change on the sheet) will give a new combination of wins and losses.
A few words to explain the formula.
This part of the formula IF(RAND()<$B$2/100;15;-10)
does the main work. RAND() tries more or less successfully to generate random numbers from 0 to 1. This number can be regarded as a percentage. And in cell B2, judging by your description, there is the desired percentage of victories. It is enough to divide the number from B2 by 100 and these values can be compared. The IF() function does exactly that - if the generated random number is included in the percentage of wins, then the result is “Win”, otherwise “Loss”.
However, if you use only this generator, the result may differ from the desired by several numbers.
Therefore, the “generator” is wrapped in two more functions IF() - “if the required number of wins has already been generated, then the LOSS” and vice versa “if the required number of losses has already been generated, then WIN”
The number of already generated WINS is calculated using COUNTIF(A$5:A5;15) - this is the number of WINS in all cells above the current one. When stretching the formula, the second part of the range will automatically increase - A$5:A6, A$5:A7, and so on - because it is specified by a relative reference, without a dollar sign in front of the row number. The number of losses is calculated in the same way, only the second parameter in the function is not 15, but -10
The required number of wins is calculated as ROUNDUP($B$2*150/100)
, and the number of losses is (150-ROUNDUP($B$2*150/100))
.
In order not to calculate the required number of wins and losses each time, you can calculate them separately. For example, put in cell C2 the formula =ROUNDUP(B2*150/100)
, and in cell D2 =150-C2
. And instead of the usual RAND() function, you can use the new RAND.NV() function
Now the generator formula can be written a little shorter
=IF(COUNTIF(A$5:A5;15)>=$C$2;-10;
IF(COUNTIF(A$5:A5;-10)>=$D$2;15;
IF(RAND.NV()<$B$2/100;15;-10)))