It may be advantageous to modify pin() to take the length as a parameter (you could build in a default length of 4). This would allow you to write tests for the sub that require no knowledge of the implementation, and (to quote BrowserUK) "a modification by someone not understanding the significance of "%04d"" would not be (as much of) a risk because the length would not be hard-coded.
Taking this one step further, pin() could also take the character set to be used for PIN generation (0..9 could be used as a default).
While these ideas may be overkill for your current application, a generalized solution might be a nice snippet that could be reused elsewhere. It would even come with a test suite. :-)
In reply to Re: Testing Random Code
by bobf
in thread Testing Random Code
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |