global-functions: $GetRandomNumber: use $GetRandomSha256

This commit is contained in:
Christian Hesse 2020-06-18 12:51:09 +02:00
parent 529dbbe4f8
commit 12015af855

View file

@ -305,16 +305,22 @@
}
# generate random number
# Warning: This is a *very* weak algorithm and in *no way*
# useful for cryptography or similar!
:set GetRandomNumber do={
:local Max ([ :tonum $1 ] + 1);
:local Sum 0;
:foreach Interface in=[ /interface find ] do={
:set Sum ($Sum + [ /interface get $Interface tx-byte ]);
:global GetRandomSha256;
:local Num;
:local Sha256 [ $GetRandomSha256 ];
:for I from=0 to=63 do={
:local Char [ :pick $Sha256 $I ];
:if ($Char~"[0-9]") do={
:set Num ($Num . $Char);
}
}
:return ($Sum % $Max);
:return ([ :tonum [ :pick $Num 0 18 ] ] % $Max);
}
# generate random sha256 string