$r() in the script isn't the <text> part, it's the <position> parameter, ie it tells /did -i where to insert %i, which is the <text>. So all numbers from 1 to 9999 get to be added, by a series of insertions at a random position. Btw, the syntax of the command is
/did -i <dname> <id> <pos> <text>
I thought I remember reading before that $r() is not always random.
$rand() has been fixed since v 6.1, so this isn't true anymore. Even in versions prior to 6.1 though, that particular $rand bug in this particular script would affect the 'randomness' of the distribution VERY little (explaining that would require a lengthy analysis, which I won't get into here).