Problem 1089. Create a random vector of integers with given sum
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
char(random_sequence(26,25420)+'A'-1)
This task is related to problem 1090
The "Test Suite" will check the sum, the mean, and the distribution.
Note: Solutions wrapped in eval(c), inline, str2func, regexprep (dynamic regular expressions), etc, are not appreciated.
Solution Stats
Problem Comments
-
3 Comments
The question does not clearly mention the length of the vector to be created. Can you rephrase the question plz ?
@Sunil, there is no constraint on the length of the vector. It can be anything, as long it satisfies the conditions specified in the problem description and the test suite.
@Dyuman Joshi, I don't get it. The problem description says "Therefore, the length of the vector is determined by m and s." and they "will check the sum, the mean, and the distribution." What are the conditions to be satisfied is not given. Only the sum is specified. May be it should be specified clearly in the problem description.
Solution Comments
Show commentsProblem Recent Solvers52
Suggested Problems
-
8876 Solvers
-
Back to basics 12 - Input Arguments
594 Solvers
-
Determine if input is a Narcissistic number
195 Solvers
-
Replace multiples of 5 with NaN
439 Solvers
-
Given a matrix, swap the 2nd & 3rd columns
1051 Solvers
More from this Author31
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!