(07-22-2020, 03:44 PM)Shannon Wrote: In order to avoid #1, I always have a variable that I use to store a numerical value that is a whole number, but not restrained to a short range of numbers as declaring an integer sometimes is, and I initialize it at 0. Then whenever I need a number bigger than the last instance, I simply increment it, and copy it's value to whatever I need to use it for,
yes that is usually sufficient but in my particular scenario, I have the additional requirements:
1. The nonce value is persistent on the exchange side meaning if I restart my side, I cannot restart the counter to 0
2. nonce value is used from 2 different machines.
With those constraints, it seems that the simplest way is to base the nonce on the UNIX timestamp with a msec granularity stored into a 64 bits integer and accept the occasional collision. When a collision occurs, I simply delay the next call attempt with some random time interval (to avoid more collision) and it usually works fine. However, in order to work fine, you need to have the time reasonably synchronized between the 2 machines. Otherwise, if machine A sends a Nonce value that is much ahead in time, machine B, even with the retry mechanism, will fail to use a nonce higher than the one used by machine A.