miners choose a value for generated_value, hash it and hope it comes out with the required number of zeros, if not they try again, and again, and again until they (or someone else) finds a value.
for simplicity let's say the fn(x) = x.
difficulty of 5? hash must have 5 zeros at the beginning: 00000XXXXXXXXXXXXXXXXXXXXXXXXX
10? must have 10: 0000000000XXXXXXXXXXXXXXXXXXXX
each zero you add on requires exponentially more time.
Example:
Treshold = 001010
If you check 001011 or 001001 then the number of leading zeros are the same but one number is below the threshold and the other is not.
Threshold is 001010
The numbers 001001 and 001011 have the same number of leading zeroes but one is below the threshold and the other is not.
For a more concrete example, if the requirement is that a 16-bit word is less than 4096, you only have to verify that it leads with 4 zeros.
I've always thought that's how it worked since that is what is written in the original Bitcoin paper (which has for a long time been my only source of information on the protocol).