How to construct a random size, random integer array with (exact) target sum value with a single Excel function (or 'best' viable/working solution given the 'known' volatile issue with this sort of construct)?
Must haves:
- Single Excel fn
- No helper function
- No bespoke VBA, Lambda named ranges, explicit/manual solver method
- Constraints: sum to exact target value (given), lower / upper dimension (array size given)
Example parameters:
- random size of between 5-30 (random) integers
- target sum, say: 1000
Similar Qs/shortcomings:
- Here - very similar question but not random size array, and summation does not always hit the target mark (sometimes overshoots/undershoots by 1-2 integers)
- Other solutions to this/related rely upon helper functions or reference the Microsoft 'known bug' issue relating to volatile nature e.g. sequence(randbetween())
In play:
- Whilst no direct resolve for the intermittent
#spill!errors appears to exist, approaches of the form:iferror(sequence(100,,0,0)+volatile,"")would be acceptable - I have a draft soln that hits the target sum (exactly, each time - I think!) whenever entire sheet calculated (since
f2 + enterotherwise avoids the#spill!), but hoping for a more succinct independently derived solution, in first instance
