If you set a brand-new code and then you forget what it was, you will be in a bad spot. Unlike forgetting your online password, you will not be able to create a new code (as you will need to unlock it first). Not all locks will be like this, but a majority of them will be.
Hence, this is why it is recommended to write your code down somewhere. Heck, you could even save it in a Word document and then store the file on an external hard drive (that way you always have it).