Function Problems

Generate Random Numbers With a Required Sum and Odd Count in WPS Spreadsheets

Huma Ashraf ChHuma Ashraf Ch Nov 20, 2026 870 views

Question details

Generate 10 random numbers from 1 to 100 with a total between 240 and 250 and exactly five odd numbers.

Generate Random Numbers With a Required Sum and Odd Count in WPS Spreadsheets
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.
Before you start

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.

Solution 1Recommended

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.

1
Enter the target

In cell D1, enter an odd target such as 245.

2
Generate five odd numbers

In A1, enter =2*RANDBETWEEN(0,19)+1, then fill the formula down through A5.

3
Generate four even numbers

In A6, enter =2*RANDBETWEEN(1,20), then fill the formula down through A9.

4
Calculate and check the final number

In A10, enter =$D$1-SUM(A1:A9). In D2, enter =IF(AND(A10>=1,A10<=100,MOD(A10,2)=0),"Valid","Recalculate").

5
Recalculate if needed

If D2 says Recalculate, press F9 to generate another set. When D2 says Valid, A1:A10 meet the requirements.

Generate Nine Random Numbers and Calculate the Tenth
Random values can change: RANDBETWEEN values can change when the worksheet recalculates. To keep a valid set, copy A1:A10 and use Paste Special > Values.
Create constrained random numbers

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. 1. Set a target: Open a blank workbook in WPS Spreadsheets and enter 245 in D1.
  2. 2. Create odd numbers: Enter =2*RANDBETWEEN(0,19)+1 in A1 and fill it down through A5.
  3. 3. Create even numbers: Enter =2*RANDBETWEEN(1,20) in A6 and fill it down through A9.
  4. 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.
Generate random integers with RANDBETWEENCheck the final number against the required rangeOpen and save Microsoft Excel XLSX filesUse a familiar spreadsheet interface
microsoft office alternative - wps office

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.