How is the probability of a sequence occuring with BLAST calculated?
According to BLAST documentation statistics of local sequence alignment, when doing database searches, is done


  by treating the database as a single long sequence of length N.


N is therefore a sum of all sequences with varying sizes from a given database.

Underlying assumption is that 


  query is a priori more likely to be related to a long than to a short sequence, because long sequences are often composed of multiple distinct domains.


To calculate the probability, we need to choose a scoring scheme (for ungapped example: choose a mismatch penalties), which for a query sequence gives us a statistically significance score $S$. Expected number of alignments with score of at least $S$ follows Gumbel extreme value distribution:

$$
E = Kmn\cdot e^{-\lambda S}
$$

where m is query length, $n=N$ and $K$ and $\lambda$ are distribution params.

Again, according to docs and its references, probability of finding at least one such seq would be $P=1-e^{-E_{(N)}}$, where $E_{(N)}$ is E-number for concatenated N-sequence and query sequence.