Amm0
September 4, 2021, 5:22pm
1
Found a new “:rndnum” command at the top level of CLI. (On RB1100Dx4, 7.1rc2)
However, it doesn’t seem to do much. I’d imagine it should generate a random number, but doesn’t:
[skyfi@bigdude] > :put [:rndnum from=1 to=100]
1
[skyfi@bigdude] > :put [:rndnum from=1 to=100]
1
It seem to always return the “from” parameter.
See:
:for from=1 to=10 counter=x do={:put [:rndnum from=1 to=10000]}
1
1
1
1
1
1
1
1
1
1
or if you really want to push the Monte Carlo effect, even 100 still results in same “from”:
{:local results {""}; :for from=1 to=100 counter=x do={:set ($results->$x) [:rndnum from=1 to=100]}; :put $results;}
;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1
;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1
Seemingly only use the “from” as the resulting “:rndnum” (note: $x is form 1..100, so its expected to be a sequence):
{:local results {""}; :for from=1 to=100 counter=x do={:set ($results->$x) [:rndnum from=$x to=100]}; :put $results;}
;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50;51
;52;53;54;55;56;57;58;59;60;61;62;63;64;65;66;67;68;69;70;71;72;73;74;75;76;77;78;79;80;81;82;83;84;85;86;87;88;89;90;91;92;93;94;95;96;97;98;99
;100
Attempting to use a “float”, get wackier results, still never random
[skyfi@bigdude] > :put [:rndnum from=1.0 to=2.0]
16777216
[skyfi@bigdude] > :put [:rndnum from=1.0 to=10.0]
16777216
[skyfi@bigdude] > :put [:rndnum from=0 to=1.0]
0
Since it’s new, imagine it’s still underdevelopment – but also not working.
:rndnum work with algoritm than is applied and from must be bigger than to, I do not know the algorithm, just produce random mumbers
:put [:rndnum from=2 to=1]
use rndstr: on lenght you decide the size, on from what characters or number use.
Examples:
Random decimal number of lenght 3
:put [:rndstr length=3 from="0123456789"]
Random hexadecimal number of lenght 4
:put [:rndstr length=4 from="0123456789abcdef"]
Random lowercase string
:put [:rndstr length=4 from="abcdefghijklmnopqrstuvwxyz"]
Random 12 mixed case string with numbers
:put [:rndstr length=12 from="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"]
Random 20 mixed characters password generator (removed on purpose " $ ’ / ? \ ` ~ for not create confusion or a problem with script)
:put [:rndstr length=20 from="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#%&()*+,-.:;<=>@[]^_{|}"]
Amm0
September 5, 2021, 1:17am
3
Ah… The “from” is might be source (in :rndnum, guessing the MAX) with “to” being the min. That’s backwards from the way I think about from (MIN) and to (MAX). Still not sure I understand the parameters since:
to=1 and from=2 gets negative numbers:
[skyfi@hap94] > {:local results {""}; :for from=1 to=100 counter=x do={:set ($results->$x) [:rndnum to=1 from=2]}; :put $results;}
;8476474455839305028;8544184727600607683;-2246353859571496977;-7101091318149709512;-3664276175342330693;-4737474446651756789;1832803795490077800;8336058322254694183;724909
1119864006909;4350144184676059189;-1703782945768826997;-6835533487544390621;7198573113838871301;2918195801509582859;-1140760128910769652;1844716598400944548;-4338859947308
002705;-8249798566517249379;-3095188413626693337;-4097858849039953336;-6941189421560107147;584282569984083278;8765575166942695755;-1266445622259634156;2266112211094233131;
1684005595691227978;-6675178252308194502;1833278133387473092;3529088692556751954;-8313826322121586677;-3684228567267250584;6347592089983726021;-4977327275701312839;5957526
083044817597;-7509603506103202611;-3145863185207133614;6727216176179535672;-274610468910482499;-4285644166103243690;-3160618908918334102;-4905421025501312968;-103871142489
3668944;2275091499265208116;8360578696188916586;2418636493674516182;-3789500904180295135;1708563618886977583;-6030449947740403774;-7882809441867287546;2920931475675805907;
5980579611957787654;5729091807395470330;-3347164787247339365;-2465534781011037575;1251986633269783847;7834477126453401324;7918597192973968521;-5480836595635473201;-3678679
537708046690;-4039467572933157193;379482471707324245;3586558130057421819;-3551764288045974000;-4335159649807033261;8162815204895929479;-3252815461153246422;433905930231505
099;-3780147673163320708;-1735827769392781661;1664805829153779261;-7727666768535315504;-4255325818806428876;2325503921762022253;8550689817430240610;-5008168741795799580;51
5041618224630343;-780369344516727013;6256044165388375120;6695088972679457424;237576667790366986;6223539940604573669;-8655170895602853952;7322619908360335448;55211740393288
53006;7154419142054859666;-4396567515518450855;-2261753001454535810;-7137350745491589521;-2444609563382340774;337193624643032794;-261175899581334743;-7909299675487124527;8
428284372749047350;-6457596538758574870;3619681125486159019;1494429900212294378;-9131779256764270933;-6825872207050300539;1723759137644695659;-2393217355391004030
but totally right if “from” is larger than “to”… it looks random integers:
{:local results {""}; :for from=1 to=100 counter=x do={:set ($results->$x) [:rndnum to=0 from=100]}; :put $results;}
;3804589401;1062964476;151031510;4152553718;3508680242;830591587;236849334;1210289154;1006102533;387466724;1036465239;2959583710;1895393125;3397400713;3054828357;792026581
;4069946749;1772077559;1626874514;2227627839;338194055;1442110500;1338958321;2459695616;848552059;1459165577;2053142992;2732862470;1061358644;139976177;2901055627;24957931
06;2051608352;1141573794;3224748299;2972907485;3469835975;1417831891;1939652651;3824763182;1030097923;812577118;2045718447;3304651758;218377910;1988465950;3436860449;96784
5719;2763496112;2839946573;1167057378;2599557987;1427010056;653069496;1416277965;958596537;1695667580;2956233660;3553152042;1859502400;3387087963;3997448692;409338406;2031
31767;1471671788;661493598;355617320;3272546428;2689050277;2688105054;3345172045;3424142316;3921904265;609553209;3720361469;549215822;3863990009;3845009420;3089241748;3649
901263;299865117;1032454014;2911218939;586355716;1440427329;403433730;1790828825;1849667339;2610128173;1722007955;1704413416;155630791;3734778169;3230728875;1718706014;307
8654386;1157676202;378044220;4199881167;284676697
Not critical issue, just seemingly odd in v7…
for me :rndnum is totally useless from the existence of :rndstr …
:rndstr with the examples I have provided, cover all randomness necessity.
mrz
September 5, 2021, 7:20am
5
:rndnum will be fixed in next rc.
Thanks, but please explain how it mean to works exactly???
:rndstr is more flexible and complete, making rndnum useless…
Can be modified other functions like [:find string RegEx start]?
Please, FIX also :toip that do not convert string to ip-prefix (or add :toipprefix), broken from…???
Example:
:global simulatingipprefixreadedfromfile "151.99.147.2/28"
:put [:typeof $simulatingipprefixreadedfromfile]
:put [:typeof [:toip $simulatingipprefixreadedfromfile]]
# i must use this "hack" to convert string containing ip-prefix on... ip-prefix data type
:global simulatingipprefixreadedfromfile [[:parse ":return 151.99.147.2/28"]]
:put [:typeof $simulatingipprefixreadedfromfile]
@Amm0
for your info:
:local array1 {“”} create non-empty array with one empty string element
:local array2 [:toarray “”] create one empty array
:global array1 {""}
:global array2 [:toarray ""]
:put [:typeof $array1]
:put [:typeof $array2]
:put [:len $array1]
:put [:len $array2]
and about this:
:for from=1 to=10 counter=x do={ :put $x }
you can use this simpler syntax for do the same:
:for x from=1 to=100 do={ :put $x }
The step is 1, if different step must be used, like pair numbers from 2 to 100:
:for x from=2 to=100 step=2 do={ :put $x }
mrz
September 5, 2021, 8:42am
8
rndnum is definitely not useless if you need to generate random numbers and rndstr is reasonable to use only if the result should be a string. It is not feasible to use rndstr to generate random numbers, because to get a random number from a string:
you extract “from” string length
call random number generator to pick a character from the string
convert character to the number
instead of just returning random number directly.
Ok, but without know the final syntax of :rndnum…
If I need a random number of exactly 4 digit, the syntax must be:
:put [:rndnum from=1000 to=9999]
on this way I never want a value between 0 and 999 because are less than 4 digit.
The final result work on this way?
mrz
September 5, 2021, 9:23am
10
Obviously range 1000-9999 return numbers from that range, not from 0-999
Amm0
September 5, 2021, 2:42pm
11
@rextended , They didn’t take out :rndstr – that seems to work the same in v7. rndstr and new rndnum differ in the types they return…
:put [:typeof [:rndnum to=1 from=100]]
num
:put [:typeof [:rndstr length=8 from=01234567890]]
str
So for fixed length things, rndstr makes sense. But if what you want, for example, is pick a random VLAN ID from 2 to 4094, sternum might be useful.
Amm0
November 29, 2021, 5:32pm
12
Okay in v7.1rc7 this mostly works now!
:put [:rndnum from=1 to=10]
8
still a small issue if the are reversed:
:put [:rndnum to=1 from=10]
-3602894572049973481
Not sure what should happen there. Maybe [:nothing] be more expected (that is a non “num” type, not a bad joke). Or, simply using the smaller of from= or to= as the “start” and bigger of the two values as the “end” – solve the need for an error since :rndnum to=1 from=1 should get 1 and does:
:put [:rndnum from=1 to=1]
1