mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2024-05-11 05:55:19 +00:00
global-functions: $GetRandomNumber: use $GetRandomSha256
This commit is contained in:
+12
-6
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user