How to Create a Balanced Random Array from 1 to 5 in Excel
Question details
The user needs to generate a 17-row by 14-column array containing values from 1 to 5 in nearly equal quantities.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Planning a physical layout (such as a tile-style assignment) where five different styles need to be distributed randomly but ordered in equal quantities.
- Observed behavior
- Generating a grid of 238 cells where the numbers 1 through 5 appear approximately 47 or 48 times each in a completely randomized layout.
Ensure your spreadsheet software supports modern dynamic array functions like RANDARRAY, SEQUENCE, VSTACK, and WRAPCOLS, as these are required to build and shape the data automatically.
Use Dynamic Arrays to Generate, Randomize, and Shape the Data
By combining SEQUENCE, VSTACK, SORTBY, RANDARRAY, and WRAPCOLS, you can enforce an equal distribution of values before shuffling them into a grid.
A standard RANDARRAY formula cannot guarantee an equal distribution of numbers. To achieve a perfectly balanced grid, you must first create the exact number of required values, combine them, shuffle them, and then shape them into the final dimensions.
For a 17x14 grid, you need 238 total cells. Dividing 238 by 5 (your maximum value) gives 47 full sets of the numbers 1 through 5, with a remainder of 3 cells.
Use the SEQUENCE function to create 47 instances of each number. For example, SEQUENCE(47, 1, 1, 0) generates 47 ones, while SEQUENCE(47, 1, 2, 0) generates 47 twos.
To fill the remaining 3 cells out of 238, use RANDARRAY(3, 1, 1, 5, TRUE) to generate three random integers between 1 and 5.
Wrap the five SEQUENCE formulas and the single RANDARRAY formula inside a VSTACK function. This combines all 238 values into a single vertical column.
Use SORTBY to shuffle the stacked array. The syntax will be SORTBY(stacked_array, RANDARRAY(238)), which sorts your exact distribution into a completely random order.
Finally, nest the randomized column inside WRAPCOLS(randomized_array, 17) to distribute the data into 17 rows and 14 columns.

Easily Generate Complex Arrays with WPS Spreadsheet
WPS Office provides comprehensive support for modern dynamic array functions. You can seamlessly manage complex data distributions, randomize variables, and shape arrays for your projects without any hassle.
- 1. Open WPS Spreadsheet: Launch WPS Office and create a new blank workbook.
- 2. Select the Target Cell: Click on the top-left cell where you want your 17x14 randomized grid to begin.
- 3. Enter the Formula: Paste the combined dynamic array formula utilizing VSTACK, SEQUENCE, and WRAPCOLS into the formula bar.
- 4. Generate the Grid: Press Enter to instantly populate the randomized, balanced array across the necessary rows and columns.

Frequently Asked Questions
Why shouldn't I just use the RANDARRAY function by itself?
Using a simple RANDARRAY(17, 14, 1, 5, TRUE) will generate random numbers from 1 to 5, but it relies purely on chance. It will not guarantee an equal distribution of each number, which is necessary if you are ordering specific quantities of physical items based on the grid.
Can I freeze the numbers so they stop randomizing?
Yes. The RANDARRAY function is volatile and recalculates whenever you make an edit to the spreadsheet. To make your balanced array permanent, select the entire 17x14 grid, copy it (Ctrl+C), and then use Paste as Values (Ctrl+Shift+V) over the same area.
How do I adjust this formula for a different grid size?
To change the dimensions, you must multiply your new rows by columns to get the total cell count. Divide that count by your maximum number to find the new SEQUENCE length. Then, update the WRAPCOLS row count parameter and the RANDARRAY sizes to reflect the new dimensions and remainder.




