Probability of line intersection Consider a square with sidelength $S$.
$n>3$ points are placed randomly within or on the edges of the square. The $i$-th point is denoted by $P_i$.
We denote a line as two points $(P_i,P_{i+1})$ and we will do so for all $1\le i<n$, generating a sequence of connected line segments.
We will add one last line $(P_n, P_1)$ to the sequence, as our sequence of lines is to be one large "loop".
What is the probability that there is at least one point of intersection between any of the line segments in the sequence? Can it be represented in terms of $S$ and $n$?
To clarify, due to the nature of the line generation, a start point of a line is always the end of another and vice-versa; a point may be shared between two lines, this will not be considered an intersection.
I don't have a really strong background in probability, but this question arose when I tried to generate a non-intersecting line sequence with Python. Using $S=800$ and $n=100$, the computation did not complete before I stopped the program, so it seems that there is some sort of exponential increase in time as $n$ increases.
 A: How many pairs of lines do we have to check for intersection?
Given a sequence of $N$ points, there are $N$ lines between conseutive points including $\overline{P_NP_1}$. Notice that $\overline{P_iP_{i+1}}$ cannot intersect itself or $\overline{P_{i-1}P_i}$ or $\overline{P_{i+1}P_{1+2}}$ so each line can intersect $N-3$ lines. That means we have to check $n=\frac{N(N-3)}{2}$ pairs of lines beacuse order doesn't matter.
What is the probability $p$ that two random line segments in a square intersect?
In a convex quadrilateral the probability of two non-adjacent lines to intersect is $\frac{1}{3}$. And by Sylvester's four-point problem the probability of four random points in a square having a convex hull is $\frac{25}{36}$. So $p = \frac{25}{108}$

What is the probability of at least one intersection?
Let $X$ be the total number of intersections which is following a binomial distribution:
$$P(X>0) = 1-P(X=0) = 1- \binom{n}{0}p^0(1-p)^{n-0} = 1-(1-p)^n$$

The probability that there is at least one intersection in a closed sequence of $N$ line segments in a square is therefore:
$$1-\left(\frac{83}{108}\right)^{N(N-3)/2}$$
