Skip to content

Commit

Permalink
Iterate over sequence of characters, not positions (#1163)
Browse files Browse the repository at this point in the history
Implementing an idea from @wendellpiez: Instead of iterating over a
numeric sequence that represents the position of each character in a
long string, iterate over the sequence of characters.

This change is in the implementation only, not in the function output.
I used ad hoc modifications of the label="seq-length=10000" scenario
in the XSpec test to check that the original and modified functions
produce the same UUID sequence.
  • Loading branch information
galtm authored and aj-stein-nist committed Jul 10, 2023
1 parent 9c0e21a commit 48af7dc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/utils/util/resolver-pipeline/random-util.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ v4 UUID
<xsl:sequence use-when="function-available('random-number-generator')">
<xsl:variable name="PRNG" as="map(xs:string, item())" select="random-number-generator($seed)"/>
<xsl:variable name="template-length" as="xs:integer" select="string-length($template)"/>
<!-- Draw one long stream from PRNG, advancing state in each iteration. -->
<xsl:variable name="template-char-seq" as="xs:string*"
select="$template ! string-to-codepoints(.) ! codepoints-to-string(.)"/>
<!-- Draw one long stream from PRNG over sequence of characters in concatenated template,
advancing state in each iteration. -->
<xsl:variable name="random-chars" as="xs:string">
<xsl:value-of>
<xsl:iterate select="(0 to ($seq-length * $template-length - 1))">
<xsl:iterate select="for $idx in (1 to $seq-length) return $template-char-seq">
<xsl:param name="PRNG" as="map(xs:string, item())" select="$PRNG"/>
<xsl:variable name="this-char" as="xs:string"
select="substring($template, (1 + current() mod $template-length), 1)"/>
<xsl:apply-templates select="$this-char" mode="uuid-char">
<xsl:apply-templates select="current()" mode="uuid-char">
<xsl:with-param name="PRNG" select="$PRNG"/>
</xsl:apply-templates>
<xsl:next-iteration>
Expand Down

0 comments on commit 48af7dc

Please sign in to comment.