aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2020-06-18 12:51:09 +0200
committerGravatar Christian Hesse <mail@eworm.de>2020-06-18 12:52:59 +0200
commit12015af85500a7bf836bb64478f07efc1e4672e3 (patch)
treee6f7e1354c1ee3c222919952816de1f1f74d30e3 /global-functions
parent529dbbe4f811653ffcf176ef7f0242ef892c8fe3 (diff)
global-functions: $GetRandomNumber: use $GetRandomSha256
Diffstat (limited to 'global-functions')
-rw-r--r--global-functions18
1 files 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