mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-06-20 17:05:44 +02:00
global-functions: $GetRandomNumber: use $GetRandomSha256
This commit is contained in:
parent
529dbbe4f8
commit
12015af855
1 changed files with 12 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue