Improve SYS_RandomInt()

rand() returns a value between 0 and RAND_MAX.

On my Debian GNU/Linux system I have RAND_MAX = 2147483647 so that should be enough but some other systems may be more limited (like 32767).

Proposed improvements:

  • return a LONG instead of int with all the range covered by random bits. So that a hCard handle (LONG) is random for all its bits.
  • not using the naive scaling of the rand result to the required interval, as this is not a correct transformation. (maybe use a modulo operation like fStart + random % (fEnd - fStart))

See "[Pcsclite-muscle] Possible generation of duplicate SCARDHANDLE" for more details http://lists.alioth.debian.org/pipermail/pcsclite-muscle/Week-of-Mon-20160801/000673.html

Copied from https://alioth.debian.org/tracker/index.php?func=detail&aid=315434&group_id=30105&atid=410088