How IPFS locates a specific file?

In IPFS each peer randomly stores and shares any file that results in any hash. That means, the file is not distributed according to some mechanism, rather it’s random.
That file hash is used to identify the file over the P2P network of IPFS.
So now, how the system looks for that specific hash among thousands of peers?
Does it use flooding or DHT?
If it uses DHT, then how the DHT locates the peer (or finds nearest peer) that holds the file while the file doesn’t follow any distribution mechanism?

In general, node operators control which files their nodes store. It’s not random.

It uses a DHT.

It uses a node lookup, probably similar to this. I’m not 100% sure on the implementation details for IPFS, though.