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



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

  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
(http://comments.gmane.org/gmane.comp.gnome.lib.xml.general/13910) 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
https://github.com/nils-werner/libxslt/compare/master...seedrand.patch

  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/>
http://www.exslt.org/math/functions/random/index.html

  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:

http://git.gnome.org/browse/libxslt/commit/?id=3fcf11ead6ad226227b0a3ef4cc6565b8d5857ff

  thanks a lot :-) !

Daniel

-- 
Daniel Veillard      | Open Source and Standards, Red Hat
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | virtualization library  http://libvirt.org/


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