For a unique 4-byte integer, you could use the system clock. For PCs, it started at 0 and increases at approximately 18.2065 times a second. The value 0 was assigned to the morning of Jan. 1, 1970 at midnight.
The counter can count up to about 4 billion before it will overflow. You could use this value if an 18th of a second is adequate resolution. Keep track of the last clock value you used. If it is not the same as the new one, append one or two zeroes. If it is the same, increment the suffix to 01 see if that was the same as the last number you generated; if the same, try 02 ...
The clock value is available from the operating systems, Word, Excel, VBA, etc., but the operating system clock access functions return a new value only once a second. The hardware clock is not very accurate. In actual operation, they gain or lose about 5 to 15 seconds per day, with 10 seconds per day being typical. Although the hardware clock usually outperforms the software clock, its performance pales in comparison to even a low-cost wristwatch. HOWEVER, in this application, we DO NOT care about acuracy, only uniqueness.
(The remainder of this note is extracted from a Novel web page:
http://developer.novell.com/research/appnotes/1994/january/03/index.htm)
The real time hardware clock can be addressed by placing a command in I/O port 70h, then reading back the result from I/O port 71h. The simple BASIC program in Appendix A shows how it is possible to read the current time from the RTC. The PC BIOS and DOS define interrupt calls to access the time and date information held by the RTC. Most high level languages also provide functions to get and set the clock from within a program.
Appendix A: Example Programs
Example BASIC program to read the RTC:
10 REM RTCLOCK.BAS - For QBASIC or QB
20 '
30 CLS
40 DO
50 OUT &H70, 0
60 RTSECONDS = INP(&H71)
70 OUT &H70, 2
80 RTMINUTES = INP(&H71)
90 OUT &H70, 4
100 RTHOURS = INP(&H71)
110 LOCATE 1, 1
120 PRINT STRING$(20, " ")
130 LOCATE 1, 1
100 PRINT "Real Time Clock now - ";
110 PRINT HEX$(RTHOURS); ":";
120 PRINT HEX$(RTMINUTES); ":";
130 PRINT HEX$(RTSECONDS)
140 LOOP UNTIL INKEY$ <> ""
150 END
Example BASIC program demonstrating access to the NIST (National Institute of Standards and Technology, formerly NBS) time source:
10 REM NISTTEST.BAS - For QBASIC or QB
15 CLS
20 COM(2) ON
30 ON COM(2) GOSUB 200
40 T$ = ""
50 OPEN "COM2:1200,N,8,1,BIN,RB1024" FOR RANDOM AS 1
60 PRINT #1, "ATZ" + CHR$(13)
70 T$ = ""
80 T = TIMER
90 DO
100 LOOP UNTIL TIMER > T + 5
105 REM Change the line below to include international access code if required
110 PRINT #1, "AT DT 3034944774" + CHR$(13)
120 T = TIMER
130 DO
140 LOOP UNTIL TIMER > T + 60
150 PRINT
160 PRINT T$
170 CLOSE 1
180 END
190 '
200 L$ = INPUT$(1, #1)
210 PRINT L$;
220 RETURN