On Thu, Jul 5, 2018 at 11:37 PM Phil Shafer <[email protected]> wrote: > > 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
Michael, Phil, thanks! I didn't know about floor() function in XSLT/SLAX. However, looks like in extremely rare cases math:random() can return 1 because according to https://github.com/GNOME/libxslt/blob/master/libexslt/math.c#L465 random number calculation can be "(double)RAND_MAX / (double)RAND_MAX". So final solution should be "floor(math:random() * 16) mod 16". Martin _______________________________________________ juniper-nsp mailing list [email protected] https://puck.nether.net/mailman/listinfo/juniper-nsp

