We study N = 2 supersymmetric four-dimensional gauge theories, in a certain 525-02 = 2 supergravity background, called theΩ-background. The partition function of the theory in the Ω-background can be calculated explicitly. We investigate various representations for this partition function: a statistical sum over random partitions, a partition function of the ensemble of random curves, and a free fermion correlator. These representations allow us to derive rigorously the Seiberg-Witten geometry, the curves, the differentials, and the prepotential. We study pure 525-03 = 2 theory, as well as the theory with matter hypermultiplets in the fundamental or adjoint representations, and the five-dimensional theory compactified on a circle.