Function Problems

Create a Nearly Equal Random 17-by-14 Array in Excel with RANDARRAY

Elise WilliamsElise Williams Nov 12, 2026 869 views

Question details

Create a 17-by-14 random array containing only the values 1 through 5, with each value occurring as evenly as possible.

Create a Nearly Equal Random 17-by-14 Array in Excel with RANDARRAY
Product
Microsoft Excel
Device & OS
not provided
Scenario
The user needs to randomize the positions of values 1 through 5 while filling exactly 238 cells in a 17-row by 14-column array.
Observed behavior
Because 238 cannot be divided evenly by 5, each value should appear either 47 or 48 times in the randomized result.
Before you start

Use a version of Excel that supports dynamic array functions, including RANDARRAY, SORTBY, TAKE, TOCOL, and WRAPROWS. Select a blank cell with enough empty space for the 17-by-14 spilled result.

Solution 1Recommended

Generate and randomize a nearly equal distribution with one formula

Use this formula when you need a 17-by-14 array of randomized values from 1 through 5 with counts that differ by no more than one.

The formula creates 240 repeated values from 1 through 5, shuffles them with random numbers, keeps the first 238 values, and wraps them into 14 columns. Since 238 is not evenly divisible by 5, three values appear 48 times and two values appear 47 times.

1
Select the output cell

Click the top-left blank cell where you want the 17-by-14 array to begin, such as A1.

2
Enter the balanced random array formula

Type or paste =WRAPROWS(TAKE(SORTBY(TOCOL(IF(SEQUENCE(48),SEQUENCE(,5))),RANDARRAY(240)),238),14) into the formula bar, then press Enter.

3
Allow the result to spill

Keep the 17 rows by 14 columns below and to the right of the formula cell empty so Excel can spill the complete array.

4
Create a new random arrangement

Press F9 to recalculate the workbook and generate a new randomized arrangement with nearly equal counts of 1, 2, 3, 4, and 5.

Generate and randomize a nearly equal distribution with one formula
Expected distribution: The result contains 238 values. Each number from 1 through 5 occurs 47 or 48 times, while its position in the array is randomized.
Work with dynamic arrays in WPS Spreadsheet

Create a Balanced Random Number Grid with WPS Spreadsheet

WPS Spreadsheet can help you build dynamic random number grids using modern array formulas. Enter the formula in one cell, let the result spill into the worksheet, and recalculate whenever you need a different randomized arrangement.

  1. 1. Open WPS Spreadsheet: Launch WPS Office, choose Spreadsheets, and open an existing workbook or select New to create a blank spreadsheet.
  2. 2. Choose the starting cell: Click the top-left cell for the output, such as A1, and make sure the next 17 rows and 14 columns are empty.
  3. 3. Enter the array formula: Enter =WRAPROWS(TAKE(SORTBY(TOCOL(IF(SEQUENCE(48),SEQUENCE(,5))),RANDARRAY(240)),238),14) in the selected cell.
  4. 4. Confirm the spilled result: Press Enter and allow the formula to fill the 17-by-14 output range automatically.
  5. 5. Refresh the random positions: Recalculate the spreadsheet using the available recalculation command or reopen the formula and confirm it again to produce a new arrangement.
Create randomized 17-by-14 number arrays from a single formula.Use dynamic array functions to distribute values 1 through 5 as evenly as possible.Open and edit Microsoft Excel .xlsx workbooks with compatible spreadsheet formatting.Use a familiar spreadsheet interface for formulas, recalculation, and spilled arrays.
microsoft office alternative - wps office

Frequently Asked Questions

Why do the numbers 1 through 5 not appear exactly the same number of times?

A 17-by-14 array has 238 cells, and 238 divided by 5 leaves a remainder of 3. Therefore, three numbers appear 48 times and the other two appear 47 times.

How does the formula randomize the number positions?

SORTBY sorts the repeated list of values by the random decimal values returned from RANDARRAY(240), producing a different order whenever the workbook recalculates.

How can I generate a different random array without changing the formula?

In Excel, press F9 to recalculate the workbook. RANDARRAY generates new random sort values, so SORTBY returns a newly shuffled array.

What should I do if the formula returns a #SPILL! error?

Clear any cells in the intended spill range. The formula needs 17 empty rows and 14 empty columns beginning at the cell where you entered it.

Can I change the array size or the range of values?

Yes. Change 238 to the total number of required cells, change 14 to the desired number of columns, and replace SEQUENCE(,5) with SEQUENCE(,n) for a range from 1 through n. Adjust the repeated sequence count so it creates at least the total number of cells needed.