But Hamlet was written with intention.
The point in the expression is to underline how critical coincidences are, and how correlation is not causation. It's not that Hamlet is long and nigh impossible to "randomly" generate, but that at scale, seemingly impossible coincidences do actually happen.