Re: [xslt] [PATCH] math:random() missing its seed

On Thu, Jan 24, 2013 at 08:08:54PM +0100, Nils Werner wrote:

  Hi Nils,

I recently noticed that the current implementation of math:random()
repeatedly always produces the same random numbers.

After looking into the code and digging up a few messages from 2008
( I
realised that the current implementation is missing its seed.

  Hum, right

My modifications only apply to xsltproc itself. I figured that for now
software linking to libxslt may either already have run srand() itself
or may be required to do so in order to use the lib.

  That maybe the main issue. People using it without initialization
may be fooled in expecting something randomized while it is not.

I also absolutely understand the need for a deterministic and
reproducible seed, so besides running srand(time(NULL)) once during
program startup I implemented a command line parameter --seed-rand
with wich the seed can be overridden manually.

The patch can be found at

  Patch is complete, fine and applies well. My main question is
shouldn't the random generator be initialized by default in the
library itself instead of xsltproc ?
  The documentation says nothing except it's supposed to be random <grin/>

  Basically if we don't initialize it is a false promise, but also
agreed one ought te be able to controld the to get reproductible
behaviour if needed.
  IMHO EXSLT should have allowed for an optional mecanism to seed
the number, that would have left the decision back in the stylesheet
writers hand.

  Considering how long we have shipped this way i think your patch
is a good compromise, so I pushed it as-is:

  thanks a lot :-) !


Daniel Veillard      | Open Source and Standards, Red Hat
veillard redhat com  | libxml Gnome XML XSLT toolkit | virtualization library

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]