Algorithm for generating random incrementing numbers up to a limit
-- generate ALL sequences of n natural numbers with given sum
-- should be called with n&lt;=sum
gen(n,sum):
  for i in 1..sum-n+1:
    -- next number in sequence is i
    gen(n-1,sum-i)  -- generate ALL possible sequences of remaining numbers