Skip to content

Commit 48af7dc

Browse files
galtmaj-stein-nist
authored andcommitted
Iterate over sequence of characters, not positions (#1163)
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.
1 parent 9c0e21a commit 48af7dc

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/utils/util/resolver-pipeline/random-util.xsl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,15 @@ v4 UUID
8383
<xsl:sequence use-when="function-available('random-number-generator')">
8484
<xsl:variable name="PRNG" as="map(xs:string, item())" select="random-number-generator($seed)"/>
8585
<xsl:variable name="template-length" as="xs:integer" select="string-length($template)"/>
86-
<!-- Draw one long stream from PRNG, advancing state in each iteration. -->
86+
<xsl:variable name="template-char-seq" as="xs:string*"
87+
select="$template ! string-to-codepoints(.) ! codepoints-to-string(.)"/>
88+
<!-- Draw one long stream from PRNG over sequence of characters in concatenated template,
89+
advancing state in each iteration. -->
8790
<xsl:variable name="random-chars" as="xs:string">
8891
<xsl:value-of>
89-
<xsl:iterate select="(0 to ($seq-length * $template-length - 1))">
92+
<xsl:iterate select="for $idx in (1 to $seq-length) return $template-char-seq">
9093
<xsl:param name="PRNG" as="map(xs:string, item())" select="$PRNG"/>
91-
<xsl:variable name="this-char" as="xs:string"
92-
select="substring($template, (1 + current() mod $template-length), 1)"/>
93-
<xsl:apply-templates select="$this-char" mode="uuid-char">
94+
<xsl:apply-templates select="current()" mode="uuid-char">
9495
<xsl:with-param name="PRNG" select="$PRNG"/>
9596
</xsl:apply-templates>
9697
<xsl:next-iteration>

0 commit comments

Comments
 (0)