From f49b67f5e7f938b881acbb2fbce8be5b3261bfea Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 26 Jul 2019 17:48:03 +0200 Subject: [PATCH] global-functions: add $GetRandom --- global-functions | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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); +}