Friends, I am trying to generate a random hex string on my web server. I am using Apache HTTPD on Windows 10. I am using the hex string for session ID's etc.
The code I have tried so far:
set /a tempone="("%RANDOM%"*"16")"
set /a RANHEXS=tempone"/"32767
@Set /a num=%random% %% 16 + 1 Echo %num% / 16
See set /?.
% is defined in the C language as
% The result of the remainder operator is the remainder when the first operand is divided by the second
And we need to escape the
% with another
So you divide a number by the range you want - so
165 %% 16 = 5 (the remainder). Then we add 1 to make it 1 to 16 else it would be 0 to 15.