From e8489b1665375d521683141d8234b42a5df514e2 Mon Sep 17 00:00:00 2001 From: Tarak Ben Youssef Date: Fri, 22 Dec 2023 18:21:06 -0600 Subject: [PATCH 1/4] add modulo behaviour in revertibleRandom --- .../version-1.0/language/built-in-functions.mdx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/versioned_docs/version-1.0/language/built-in-functions.mdx b/versioned_docs/version-1.0/language/built-in-functions.mdx index 7cab46c..07e9bc2 100644 --- a/versioned_docs/version-1.0/language/built-in-functions.mdx +++ b/versioned_docs/version-1.0/language/built-in-functions.mdx @@ -32,10 +32,17 @@ The message argument is optional. ## `revertibleRandom` ```cadence -view fun revertibleRandom(): UInt64 +view fun revertibleRandom(modulo: T): T ``` +Returns a pseudo-random integer. + +`T` can be any fixed-size unsigned integer type +(`UInt8`, `UInt16`, `UInt128`, `UInt256`, `Word8`, `Word16`, `Word32`, `Word64`). + +The modulo argument is optional. +If provided, the returned integer is between `0` and `modulo -1`. +The function errors if `modulo` is equal to 0. -Returns a pseudo-random number. The sequence of returned random numbers is independent for every transaction in each block. From 670ea81c59793e09fe0b39ab42a3cacb1ba25f56 Mon Sep 17 00:00:00 2001 From: Tarak Ben Youssef <50252200+tarakby@users.noreply.github.com> Date: Fri, 22 Dec 2023 20:41:06 -0600 Subject: [PATCH 2/4] Update versioned_docs/version-1.0/language/built-in-functions.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Müller --- versioned_docs/version-1.0/language/built-in-functions.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/versioned_docs/version-1.0/language/built-in-functions.mdx b/versioned_docs/version-1.0/language/built-in-functions.mdx index 07e9bc2..eda7692 100644 --- a/versioned_docs/version-1.0/language/built-in-functions.mdx +++ b/versioned_docs/version-1.0/language/built-in-functions.mdx @@ -41,6 +41,7 @@ Returns a pseudo-random integer. The modulo argument is optional. If provided, the returned integer is between `0` and `modulo -1`. +If not provided, the returned integer is between `0` and the maximum value of `T`. The function errors if `modulo` is equal to 0. From b12798a1031f764e99bcd47520f97af0405d23cb Mon Sep 17 00:00:00 2001 From: Tarak Ben Youssef <50252200+tarakby@users.noreply.github.com> Date: Fri, 22 Dec 2023 20:41:40 -0600 Subject: [PATCH 3/4] Update versioned_docs/version-1.0/language/built-in-functions.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Müller --- versioned_docs/version-1.0/language/built-in-functions.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versioned_docs/version-1.0/language/built-in-functions.mdx b/versioned_docs/version-1.0/language/built-in-functions.mdx index eda7692..4627265 100644 --- a/versioned_docs/version-1.0/language/built-in-functions.mdx +++ b/versioned_docs/version-1.0/language/built-in-functions.mdx @@ -32,7 +32,7 @@ The message argument is optional. ## `revertibleRandom` ```cadence -view fun revertibleRandom(modulo: T): T +view fun revertibleRandom(modulo: T): T ``` Returns a pseudo-random integer. From 08bf240b15e0740f3f96dc6abf0c1e02db2c2514 Mon Sep 17 00:00:00 2001 From: Tarak Ben Youssef <50252200+tarakby@users.noreply.github.com> Date: Fri, 22 Dec 2023 20:41:48 -0600 Subject: [PATCH 4/4] Update versioned_docs/version-1.0/language/built-in-functions.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Müller --- versioned_docs/version-1.0/language/built-in-functions.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/versioned_docs/version-1.0/language/built-in-functions.mdx b/versioned_docs/version-1.0/language/built-in-functions.mdx index 4627265..4d6d8ad 100644 --- a/versioned_docs/version-1.0/language/built-in-functions.mdx +++ b/versioned_docs/version-1.0/language/built-in-functions.mdx @@ -36,8 +36,9 @@ view fun revertibleRandom(modulo: T): T ``` Returns a pseudo-random integer. -`T` can be any fixed-size unsigned integer type -(`UInt8`, `UInt16`, `UInt128`, `UInt256`, `Word8`, `Word16`, `Word32`, `Word64`). +`T` can be any fixed-size unsigned integer type (`FixedSizeUnsignedInteger`, i.e. +(`UInt8`, `UInt16`, `UInt32`, `UInt64`, `UInt128`, `UInt256`, +`Word8`, `Word16`, `Word32`, `Word64`, `Word128`, `Word256`). The modulo argument is optional. If provided, the returned integer is between `0` and `modulo -1`.