How to Generate Random Numbers Using Median and IQR in Excel
Question details
The user wants to generate random values based on a dataset's median and interquartile range (IQR), potentially following a normal distribution.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Simulating new data or conducting statistical analysis based on the baseline properties (median and quartiles) of an existing dataset.
- Observed behavior
- The user requires the correct combination of statistical functions to calculate the IQR and generate normally distributed random numbers around those parameters.
Ensure your source dataset is clean and organized in a single column or row. You should also decide whether your generated numbers must strictly fall within the first and third quartiles or if they can approximate a normal distribution.
Use Statistical Functions and NORM.INV to Generate Values
Calculate the median and quartiles first, derive the IQR, and then use the NORM.INV and RAND functions to generate normally distributed random numbers.
This method uses an approximate normal-distribution approach. It generates values around the specified range but does not strictly guarantee that every single result will fall exactly between the first and third quartiles.
Select an empty cell and use the formula =MEDIAN(data_range) to find the middle value of your dataset.
In two separate cells, calculate Q1 using =QUARTILE.INC(data_range, 1) and Q3 using =QUARTILE.INC(data_range, 3).
Subtract your Q1 result from your Q3 result to find the IQR (e.g., =cell_Q3 - cell_Q1).
Use the inverse normal distribution formula combined with RAND(). Enter =NORM.INV(RAND(), median - (IQR / 2), median + (IQR / 2)), substituting 'median' and 'IQR' with their respective cell references.

Generate Random Numbers and Perform Statistical Analysis with WPS Spreadsheet
WPS Spreadsheet fully supports advanced statistical functions like NORM.INV, MEDIAN, and QUARTILE.INC. You can easily perform complex data simulations and statistical analysis in a lightweight, free environment.
- 1. Open Your Dataset: Launch WPS Spreadsheet and open the workbook containing your source data.
- 2. Input Statistical Formulas: Use the MEDIAN and QUARTILE.INC formulas in empty cells to establish your baseline parameters.
- 3. Apply the Random Generation Formula: Type the NORM.INV and RAND combination formula into the target cells and drag the fill handle to generate multiple values.
- 4. Lock the Values: Since RAND() is volatile, copy your generated numbers, right-click, and select 'Paste as Values' to prevent them from recalculating.

Frequently Asked Questions
Can I strictly constrain the random numbers between Q1 and Q3?
Yes. If you do not need a normal distribution and simply want uniform random numbers bounded by Q1 and Q3, you can use the formula =Q1 + RAND() * (Q3 - Q1).
Why do the random numbers change every time I edit a cell?
The RAND() function is volatile, meaning it recalculates automatically whenever any change is made to the worksheet. To keep your simulated data static, copy the cells containing the formulas and use 'Paste Special' > 'Values' to overwrite the formulas with fixed numbers.
What is the difference between QUARTILE.INC and QUARTILE.EXC?
QUARTILE.INC includes the minimum (0th percentile) and maximum (100th percentile) values when evaluating the dataset. QUARTILE.EXC excludes them. For standard statistical IQR calculations, QUARTILE.INC is most commonly used.




