Dependent "or" probabiltiy I have a $N^2$ grid of numbers ($NxN$) which is filled with $1..N^2$ numbers randomly.
How can I calculate the probability of one number $x$ having a neighbor (up, down, left or right only) that's specifically $x+1$?
For example, let $N=2$:
x y
z a

In this case, what's the probability of $y$ OR $z$ being exactly $x+1$?
(Optionally:) How can I generalize this to any $N$?
Here, I think we're talking about a dependent case, because if I choose $y$ from 3 available numbers, I can only choose $z$ from the remaining 2, however, that doesn't mean the chance increases to 1 in 2, because I might've already chosen $y$ as $x+1$.
EDIT:
It is randomly making an NxN grid from all the numbers between 1 to N. Any N as in any integer. So for 3 it's a 3x3 grid randomly filled with the numbers 1,2,3,4,5,6,7,8 and 9. If x=3 then x+1 is 4. In the generalized version, the question is if I pick any x, and what are the chances that there is x+1 in the neighborhood of x (so right above, below, left or right of x).
I think this is now clear, please remove the "unclear" tag.
 A: This grid determines a directed graph: the graph's nodes are the grid cells and when one cell shares an edge with another one, two directed edges are placed between the corresponding nodes in the graph.
Consider any finite graph $\Gamma(\mathscr{V},\mathscr{E})$ with $n$ nodes $\mathscr{V}$ connected by edges $\mathscr{E}$ (which are ordered pairs of distinct nodes).  The problem supposes the integers $1,2,\ldots,n$ have been randomly mapped onto the nodes. "Randomly" means all $n!$ such (one-to-one) mappings are equally probable.  As a matter of notation, let $\nu(i)$ be the node associated with any such integer $i.$  Given $i$ and $j,$ we will compute the chance there is an edge between $\nu(i)$ and $\nu(j).$  Clearly this is the same as the chance there is a directed edge from $\nu(i)$ to $\nu(j).$
The value of this abstract perspective is that it makes the calculation simple because it forces our attention on the minimum of information needed.
Let $d(p)$ be the "out degree," or number of nodes, with edges starting at an arbitrary node $p.$ Given $\nu(i)=p$ (an event that obviously has chance $1/n$ of occurring), the number of ways the ordered pair $(p,\nu(j))$ can be an edge is $d(p).$  Since there are $n-1$ remaining nodes to which $j$ can be mapped, and conditional on the assignment of $i$ to $p$ all those nodes are equally likely, the chance of such a connection is $d(p)/(n-1).$  The chance that $(p,\nu(j))$ is an edge is now obtained from the law of total probability by summing over all the possible nodes $p$ that might be associated with the number $i:$
$$\begin{aligned}
\Pr((\nu(i),\nu(j)) \in \mathscr{E}) &= \sum_{p\in\mathscr{V}}\Pr((p,\nu(j)) \in \mathscr{E} \mid \nu(i)=p) \Pr(\nu(i)=p)\\
&=\sum_{p\in\mathscr{V}}\frac{d(p)}{n-1}\,\frac{1}{n}\\
&= \frac{1}{(n-1)n} \sum_{p\in\mathscr{V}} d(p).
\end{aligned}$$
When, for each possible degree $d$ there are $n_d$ nodes of degree $d,$ this final sum simplifies, giving the general formula

$$\Pr(\nu(i)\text{ is connected to }\nu(j)) = \frac{1}{n(n-1)}\,\sum_{d=0}^n d\,n_d.$$

This reduces the calculation to finding how many nodes of each degree there are.
For example, on an $M\times N$ grid with $M\ge 2$ and $N\ge 2,$ there are

*

*Four corners, each connected to just two neighbors, so $n_2=4.$


*Two edges of $N-2$ cells apiece and two edges of $M-2$ cells apiece, each connected to exactly three neighbors, so $n_3=2(N-2) + 2(M-2).$


*A rectangular array of $(M-2)(N-2)$ interior cells, each connected to four neighbors, so $n_4=(M-2)(N-2).$
There are $n=MN$ nodes altogether. The answer in this case therefore is
$$\begin{aligned}
\frac{1}{(n-1)n}\sum_{d=0}^n d\,n_d &= \frac{1}{(MN-1)MN} \left(2(4) + 3(2(M+N-4)) + 4(M-2)(N-2)\right)\\
&= \frac{4MN - 2(M+N)}{(MN-1)MN}.
\end{aligned}$$
When $M=N$ this simplifies to $$\frac{4}{N(N+1)}.$$
The question is answered by setting $i=x$ and $j=x+1$ (noting that $j$ does not exist when $i=N^2$).  Thus,

When $1\le x\le N^2-1,$ the chance that $x$ and $x+1$ are adjacent in the $N\times N$ grid is $4/(N(N+1)).$

