That was fast. Thanks, Dirk! Your logic sounds good to me.

Cheers,
Amanda


> Date: Mon, 18 Aug 2014 17:10:28 +0200
> From: Dirk Kirsten <d...@basex.org>
> To: basex-talk@mailman.uni-konstanz.de
> Subject: Re: [basex-talk] random:integer vs. random:seeded-integer
> Message-ID: <53f21764.4030...@basex.org>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> 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

Reply via email to