This post covers how to do it with Excel. All you need to do along with using that post is find the format of a current valid code to plug in the 4 digits toward the end of the formula. For instance, the current $15 off $50 4 digits to put in there is (edit) 6200.
.