How to find all the N-tuples with nonnegative integers that add up to a fixed integer M I am trying to find a method to find all the $N$ tuples $(a_1,a_2,\ldots,a_N)$ where all the $a_i \in \mathbb{Z}, a_i \geq 0$ such that the sum of the elements of the tuples is exactly $M=\sum_{i=1}^N a_i$. 
An obvious way to do this is to to generate all the $N$ tuples with entries between 0 and $M$ and then select the ones add up to the number $M$.
I wonder if there is a way to obtain said $N$ tuples without going through all the possible $N$ tuples.
Geometrically this problem is like finding all the points that belong to the  hyperplane $\sum_{i=1}^N a_i = M$ in the set  $(\mathbb{Z}^{\geq})^N$.
Thanks in advance for any help!
 A: The stars and bars page referenced by Quasicoherent is what you want.  Add $1$ to all the $a_i$ to make them positive.  Now you want $N$-tuples that sum to $N+M$.  Make a line of $N+M$ stars and put $N-1$ bars to separate them.  Count the stars between the bars to get your tuple.  There are $N+M-1$ places to put bars, so $N+M-1 \choose N-1$ different tuples.
A: Generating Function approach
$$
\begin{align}
\left[x^m\right]\left(\frac1{1-x}\right)^n
&=(-1)^m\binom{-n}{m}\\[6pt]
&=\binom{n+m-1}{m}
\end{align}
$$

A Different Stars and Bars Approach
Either I misunderstand Ross Millikan's answer or this is a different approach.
Take $n-1$ bars to separate the $n$ numbers and $m$ stars to represent the numbers between the bars. The number of stars between the bars is one of the $n$ numbers. To count how many $n$-tuples there are, just count the number of ways to choose where the $m$ stars should go within the $n+m-1$ objects:
$$
\binom{n+m-1}{m}
$$
A: Recursion-like solutions would suggest themselves: generate all $N$-tuples that sum to $M-1$ and add $1$ to every coordinate of all of them. And then go back. 
A: Addendum in case anyone is looking for a software solution:
I stumbled upon this problem, and needed a Pythonic solution to list all of the allowed arrangements. This is the solution I got by reformatting code from Ben Paul Thurston:
def stars_and_bars(num_objects_remaining, num_bins_remaining, filled_bins=()):
    """
    The Stars and Bars (https://en.wikipedia.org/wiki/Stars_and_bars_(combinatorics)) problem can be thought of as
    1. Putting m-1 bars ("|") in amongst a row of n stars
    OR
    2. Putting n balls into m bins.

    This program lists all the possible combinations by doing so.
    """
    if num_bins_remaining > 1:
        # case 1: more than one bins left
        novel_arrangement = []  # receptacle to contain newly generated arrangements.
        for num_distributed_to_the_next_bin in range(0, num_objects_remaining + 1):
            # try putting in anything between 0 to num_objects_remaining of objects into the next bin.
            novel_arrangement.extend(
                stars_and_bars(
                    num_objects_remaining - num_distributed_to_the_next_bin,
                    num_bins_remaining - 1,
                    filled_bins=filled_bins + (num_distributed_to_the_next_bin,),
                )
                # one or multiple tuple enclosed in a list
            )
        return novel_arrangement
    else:
        # case 2: reached last bin. Termintae recursion.
        # return a single tuple enclosed in a list.
        return [
            filled_bins + (num_objects_remaining,),
        ]

So for example, if you'd like to list all the ways to write $N=6$-tuple of nonnegative integers such that they sum up to $M=10$, you can call the function
print(stars_and_bars(10, 6))

