Skip to content

[BUG] seeded fn:random-number-generator must be consistent within a single execution context #3915

@line-o

Description

@line-o

Describe the bug

For a vast range of seeds the randomness is not consistent within a single execution context.

  • any string not castable as xs:integer
  • any date, dateTime
  • any xs:decimal not castable as xs:integer
  • xs:integer larger than 9223372036854775807
fn:random-number-generator("a")?number eq
fn:random-number-generator("a")?number

is false()

Expected behavior

The xquery 3.1 specification clearly states that the result of fn:random-number-generator("a")?number must be the same within the same execution context.

Both forms of the function are ·deterministic·: calling the function twice with the same arguments, within a single ·execution scope·, produces the same results.

https://www.w3.org/TR/xpath-functions/#func-random-number-generator

related feature request #3912 might be implemented with a fix for this issue

To Reproduce

xquery version "3.1";

module namespace t="http://exist-db.org/xquery/test";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare
    %test:assertTrue
function t:test() {
  fn:random-number-generator("a")?number eq
  fn:random-number-generator("a")?number
};

Context (please always complete the following information):

  • OS: macOS 10.15.7
  • eXist-db version: 5.3.0-SNAPSHOT
  • Java Version Java8 1.8.0_252-b09

Additional context

  • How is eXist-db installed? built from source
  • Any custom changes in e.g. conf.xml? none

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugissue confirmed as bugxqueryissue is related to xquery implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions