Generate Random Numbers With a Required Sum and Odd Count in WPS Spreadsheets
Question details
Generate 10 random numbers from 1 to 100 with a total between 240 and 250 and exactly five odd numbers.

- Product
- Spreadsheet software, such as WPS Spreadsheets
- Device & OS
- not provided
- Scenario
- Create a set of random integers that meets both a sum range and an odd-number count.
- Observed behavior
- The desired set contains five odd and five even integers, so its total must be one of 241, 243, 245, 247, or 249.
Open a blank worksheet and choose an odd target total between 240 and 250. This method allows repeated numbers and does not produce every valid set with equal probability.
Generate Nine Random Numbers and Calculate the Tenth
Use spreadsheet formulas to create five odd numbers and five even numbers with a chosen valid total.
Five odd integers and five even integers always add up to an odd number. Therefore, the only possible totals in the requested range are 241, 243, 245, 247, and 249.
The first nine formulas use smaller numbers to make a valid tenth number more likely. The tenth number is calculated from the target and must be checked to ensure it falls between 1 and 100.
In cell D1, enter an odd target such as 245.
In A1, enter =2*RANDBETWEEN(0,19)+1, then fill the formula down through A5.
In A6, enter =2*RANDBETWEEN(1,20), then fill the formula down through A9.
In A10, enter =$D$1-SUM(A1:A9). In D2, enter =IF(AND(A10>=1,A10<=100,MOD(A10,2)=0),"Valid","Recalculate").
If D2 says Recalculate, press F9 to generate another set. When D2 says Valid, A1:A10 meet the requirements.

Build a Random Number Set in WPS Spreadsheets
Use WPS Spreadsheets formulas to generate five odd and four even random integers, then calculate and validate the tenth against your target total.
- 1. Set a target: Open a blank workbook in WPS Spreadsheets and enter 245 in D1.
- 2. Create odd numbers: Enter =2*RANDBETWEEN(0,19)+1 in A1 and fill it down through A5.
- 3. Create even numbers: Enter =2*RANDBETWEEN(1,20) in A6 and fill it down through A9.
- 4. Calculate and validate: Enter =$D$1-SUM(A1:A9) in A10 and =IF(AND(A10>=1,A10<=100,MOD(A10,2)=0),"Valid","Recalculate") in D2. If D2 says Recalculate, press F9 until it says Valid.

Frequently Asked Questions
Why can't the total be 250?
Five odd integers add up to an odd number, and adding five even integers keeps the total odd. Since 250 is even, it cannot satisfy the required odd count.
Can I use a target other than 245?
Yes. Enter 241, 243, 247, or 249 in D1 instead. The formula in A10 will use that target, and you can recalculate if the result is outside 1 to 100.
Can the generated numbers repeat?
Yes. RANDBETWEEN can return the same value more than once. The method does not enforce unique numbers.
How do I keep a valid set from changing?
After D2 says Valid, copy A1:A10 and use Paste Special > Values to replace the formulas with their current results.




