[j-nsp] format of minimum and maximum value of math:random() in SLAX

Phil Shafer phil at juniper.net
Thu Jul 5 16:38:09 EDT 2018


Michael Loftis writes:
>idk if there's a floor function but the general solution is floor(rand() *
>16) when rand() produces values 0-1(exclusive) IE if random does not
>generate 1.0 - dunno implementation details for slax

Yes, XPath has a floor() function that can be used directly in SLAX.

https://www.w3.org/TR/1999/REC-xpath-19991116/#section-Number-Functions

So you'd say:

    var $res = floor(rand() * 16);

Also see the "number" statement for additional number-formatting
options:

http://libslax.readthedocs.io/en/latest/content.html#the-number-statement

Thanks,
 Phil


More information about the juniper-nsp mailing list