aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions
diff options
context:
space:
mode:
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