global-functions: $GetRandomNumber: use :rndnum

This is available in RouterOS 7.x...

Signed-off-by: Christian Hesse <mail@eworm.de>
This commit is contained in:
Michael Gisbers 2022-08-04 00:53:47 +02:00 committed by Christian Hesse
parent 0562198c55
commit 28be6d097d

View file

@ -407,15 +407,9 @@
# generate random number # generate random number
:set GetRandomNumber do={ :set GetRandomNumber do={
:local Max 4294967295; :global EitherOr;
:if ([ :typeof $1 ] != "nothing" ) do={
:set Max ([ :tonum $1 ] + 1);
}
:global GetRandom20CharHex; :return [ :rndnum from=0 to=[ $EitherOr [ :tonum $1 ] 4294967295 ] ];
:global HexToNum;
:return ([ $HexToNum [ :pick [ $GetRandom20CharHex ] 0 15 ] ] % $Max);
} }
# convert from hex (string) to num # convert from hex (string) to num