In all of the cases that I know of the remote provides the code.
Simple ones have switches that you can select a few thousand different codes.
Later ones, Billion codes, had more codes. I don't know if they are like a serial number and built in or if some kind of random activity such as the lenght of time after inserting the battery sets the code transmited.
The last is the rolling code (Secuitry +) that generates a mathematical "random" code each press.
the learn buttons on the different modes learns the current code. In the coase of the rolling code the receiver also computes what the next code will be based on the formula and plus or minus 500 codes on each size in case you pressed the button out side range of the receiver.