Re: [xml] EXSLT random() function
- From: Rush Manbert <rush manbert com>
- To: Ralf Junker <ralfjunker gmx de>
- Cc: xml gnome org
- Subject: Re: [xml] EXSLT random() function
- Date: Wed, 20 Feb 2008 13:25:21 -0800
Ralf Junker wrote:
so apparently libexslt implementation might just be conformant, but
as usual we takes patches ... But I don't see how you would seed in
a truely random fashion while keeping the code portable.
replying to myself, maybe we could just use
srand((unsigned int)time(NULL))
just before xsltRegisterExtModuleFunction ((const xmlChar *) "random", ...
in exsltMathRegister()
Well possible, but calling srand() automatically can be disturbing - and hard to debug, if not known! - if a
special srand() was issued previously to run reproducable tests.
Also, as far as I understand, calling srand() automatically is only required for external libxml libraries.
If linked into applications, they can just call srand() as they please.
How about, therefore, adding a simple srand() wrapper function like (for example xmlsrand() or similar) which
applications can call to set the external library's random seed?
Ralf
If you're going to do something like this (which sounds like a good
idea), then maybe you should also consider allowing connections for 2
callback functions. One to seed the random number generator as the
library user desires, and a second to generate a random number. There
are many ways to generate random numbers (See the thread post by Roumen
Petrov), some better than others. There are also many possible ways the
library users might want to use them. Providing default behavior with
the capability to override would be potentially useful.
Just my 2 cents.
- Rush
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]