Topology of ridge patterns: randomness and constraints