aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2019-07-26 17:48:03 +0200
committerGravatar Christian Hesse <mail@eworm.de>2019-07-26 18:13:59 +0200
commitf49b67f5e7f938b881acbb2fbce8be5b3261bfea (patch)
tree436461a474e9037b4901bcc593090ede0f9d2d2c
parent25a22e2e1c8d7f2dd195e76acf29b6ae8f6c6bfe (diff)
global-functions: add $GetRandom
-rw-r--r--global-functions13
1 files changed, 13 insertions, 0 deletions
diff --git a/global-functions b/global-functions
index fb30680..6f1776b 100644
--- a/global-functions
+++ b/global-functions
@@ -245,3 +245,16 @@
}
:return $Result;
}
+
+# generate random number
+# Warning: This is a *very* weak algorithm and in *no way*
+# useful for cryptography or similar!
+:global GetRandom do={
+ :local Max ([ :tonum $1 ] + 1);
+ :local Sum 0;
+
+ :foreach Interface in=[ /interface find ] do={
+ :set Sum ($Sum + [ /interface get $Interface tx-byte ]);
+ }
+ :return ($Sum % $Max);
+}