From 12015af85500a7bf836bb64478f07efc1e4672e3 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 18 Jun 2020 12:51:09 +0200 Subject: global-functions: $GetRandomNumber: use $GetRandomSha256 --- global-functions | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/global-functions b/global-functions index e6b40ba..149838b 100644 --- a/global-functions +++ b/global-functions @@ -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 -- cgit v1.2.3-70-g09d2