The probability that a discrete function is non-decreasing 
Let $A$ and $B$ be the sets $\{1,2,\dotsc,10\}$ and $\{1,2,\dotsc,20\}$ respectively. Consider a function $A \to B$. What is the probability that the function is non-decreasing?

I know total number of functions possible is $20^{10}$. How to find number of non-decreasing functions?
 A: As you noted there are $20^{10}$ functions from $A$ to $B$.  
We can count the increasing functions with stars and bars.  Use $10$ bars and $20$ stars.   For any arrangement of the stars and bars, we can get a corresponding increasing function from $A$ to $B$  by $f(i)$ is the total number of stars to the left of the $i$-th bar.  
For example $**\mid\mid**\mid*\mid ****\mid\mid***\mid\mid*****\mid*\mid **$ corresponds to the increasing function whose respective values on $1, 2,\dots, 10$ are $2,2,4,5,9,9,12,12,17,18$.
Or conversely, the increasing function with respective values $1, 1, 3, 7, 9, 12, 12, 18, 20, 20$ is represented by $*\mid\mid**\mid****\mid**\mid***\mid\mid******\mid**\mid\mid$.
So there are ${30}\choose{10}$ non-decreasing functions from $A$ to $B$.  
The probability of randomly selecting a non-decreasing function is $\frac{{30}\choose{10}}{20^{10}}$ (See edit below.  Original answer is incorrect.)

Edit: Each string must start with a $*$ (otherwise a function value of $0$ could occur).  So that means there are $19$ (remaining) stars and $10$ bars to place freely.  This changes the probability to $\frac{{29}\choose{10}}{20^{10}}$.
Thank you to A.S. for pointing out my mistake.
A: Here is an equivalent formulation of your problem. Choose 10 samples, $\{X_1,\dots,X_{10}\}$ independently from a uniform probability distribution among the numbers $\{1,2,\dots,20\}$. What is the probability that $X_1\leq\dots\leq X_{10}$? 
Since the $X_i$ are independent this is just $P(X_1\leq X_2)\cdot P(X_1\leq X_2)\cdots P(X_9\leq X_{10})$. Then since $P(X_i\leq X_{i+1})=P(X_i\geq X_{i+1})$ by symmetry (they are independently chosen from the same distribution) and $1=P(X_i\leq X_{i+1})+P(X_i> X_{i+1})$ (they are disjoint events making up all possibilities) $1=(X_i\leq X_{i+1})+P(X_i\geq X_{i+1})-P(X_i=X_{i+1})=2P(X_i\leq X_{i+1})-\frac{1}{20}.$ Rearranging, $P(X_i\leq X_{i+1})=\frac{21}{40}$. Therefore, the probability that the $X_i$s are nondecreasing is $\left(\frac{21}{40}\right)^9$ or roughly $0.303$%
A: Here is another solution, using generating functions.
Let $m$ be the size of $A$ and $n$ be the size of $B$.
Let $P_m(n)$ be the number of non-decreasing functions from $A$ to $B$.
The first element can be any out of $m$. After choosing it, the remaining terms must also be a non-decreasing sequence. This leads to the recurrence relation
$$P_m(n)=\sum_{k=1}^nP_{m-1}(k)$$
Now let $f_n(x)=nx+\sum_{m=2}^\infty x^mP_m(n)$, where we have incorporated the fact that $P_1(n)=n$.
The recurrence relation for $P$ leads to a recurrence relation for $f$ which is 
$$f_n(x)=nx+x\sum_{k=1}^nf_k(x).$$
Now, let $g(x,y)=\sum_{n=1}^\infty f_n(x)y^n$. The recurrence relation for $f$ allows us to find that 
$$g(x,y)=\frac{xy}{(1-y)(1-x-y)}$$. 
