Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 1089. Create a random vector of integers with given sum

Created by J-G van der Toorn

Your task today is to write a function that returns a vector of integer numbers, between, and including, 1 and m, of which the sum is equal to s. Therefore, the length of the vector is determined by m and s.

For example, to create a sequence of characters 'A'-'Z', with 'character-sum' (A=1, B=2, Z=26) of 25420, use


This task is related to problem 1090

The "Test Suite" will check the sum, the mean, and the distribution.



Problem Group

17 solvers submitted 32 solutions (1.88 solutions/solver).

Loading Solution Map...

Solution Comments