image thumbnail

Random Integers With a Specified Sum and Range

version 1.0.0 (5.2 KB) by DGM
Generate random integers with specified sum and parameters from various distributions.


Updated 4 Feb 2022

View License

The function randisum() can draw random integers from a specified distribution, subject to user-specified sum and boundary constraints. Supported distributions are 'uniform', 'skew', 'exponential', and 'gaussian'.
Consider the simplistic example:
% Subdivide a vector into 10 randomly-sized blocks
x = 1:100;
blocksizes = randisum(5,numel(x),[1 10]);
xc = mat2cell(x,1,blocksizes);
I make no claims that these are particularly efficient, robust, or statistically meaningful ways to solve this problem.
Webdocs for randisum():
These tools are part of the MIMT:

Cite As

DGM (2022). Random Integers With a Specified Sum and Range (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2019b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!