Thanks, Christian!
Cheers, Amanda
Date: Tue, 19 Aug 2014 16:04:17 +0200 From: Christian Gr?n christian.gruen@gmail.com To: Dirk Kirsten dk@basex.org Cc: BaseX basex-talk@mailman.uni-konstanz.de Subject: Re: [basex-talk] random:integer vs. random:seeded-integer Message-ID: <CAP94bnObngxdY3GmJABJYsxF8Bt4WJBcyFeQf- 3QwGfrPJzAOg@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1
Hi Amanda,
I have extended Dirk's pull request and added new error codes [1]; a new snapshot is available [2].
Best, Christian
[1] http://docs.basex.org/wiki/Random_Module [2] http://files.basex.org/releases/latest/
On Mon, Aug 18, 2014 at 5:10 PM, Dirk Kirsten dk@basex.org wrote:
Hello Amanda,
I agree, this behaviour is inconsistent. I am not quite sure what is the best way to go here. Raising no error and simply returning 0 (as it is currently done for random:integer() if max is out of range) seems pretty dangerous to me, considering that randomness is often used for security and an unexpected 0 might be hazardous. Raising a Java error is maybe not the most elegant thing, maybe an XQuery error would be more elegant (like FOAR0001, see https://docs.basex.org/wiki/XQuery_Errors).
I created a small pull request, which also throws an error for random:integer() if max is out of range, see https://github.com/BaseXdb/basex/pull/985.
Cheers, Dirk
On 18/08/14 15:56, Amanda Galtman wrote:
Hi,
Is it intentional that random:integer lets you use zero or a negative value
for $max, but random:seeded-integer errors out in those cases? I know these are edge cases. I'm only flagging them because of the inconsistency between the two similar functions.
(: Returns (0,0). :) (random:integer(0),random:integer(-5))
(: Errors out :) random:seeded-integer(31,1,0)
(: Errors out :) random:seeded-integer(31,1,-5)
Here is the error information from the last command above.
Error: Improper use? Potential bug? Your feedback is welcome: Contact: basex-talk@mailman.uni-konstanz.de Version: BaseX 7.9 Java: Oracle Corporation, 1.7.0_25 OS: Windows 7, amd64 Stack Trace: java.lang.IllegalArgumentException: n must be positive at java.util.Random.nextInt(Unknown Source) at org.basex.query.func.FNRandom$1.next(FNRandom.java:85) at org.basex.query.MainModule$1.next(MainModule.java:98) at org.basex.query.QueryContext.execute(QueryContext.java:598) at org.basex.query.QueryProcessor.execute(QueryProcessor.java:101) at org.basex.core.cmd.AQuery.query(AQuery.java:82) at org.basex.core.cmd.XQuery.run(XQuery.java:22) at org.basex.core.Command.run(Command.java:329) at org.basex.core.Command.execute(Command.java:94) at org.basex.gui.GUI.exec(GUI.java:417) at org.basex.gui.GUI.access$500(GUI.java:41) at org.basex.gui.GUI$8.run(GUI.java:361)
Cheers, Amanda
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Gesch?ftsf?hrer: | Dr. Christian Gr?n, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
basex-talk@mailman.uni-konstanz.de