-
Notifications
You must be signed in to change notification settings - Fork 66
Update randomness doc #1281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update randomness doc #1281
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -377,11 +377,12 @@ function RandomValues() { | |
|
||
#### Notes: | ||
|
||
* Randomness is generated using Flow’s **on-chain `revertibleRandom`**, producing pseudorandom values tied to block and transaction execution. | ||
* The value returned for identical calls within the same block will be identical. | ||
* This hook is designed for simple use cases that **don’t require a [commit-reveal scheme]**, such as randomized UIs. | ||
* For **more advanced use cases** that **do** require a [commit-reveal scheme], Flow provides built-in support for that pattern. | ||
* Values are **deterministic**: if a transaction fails and retries, the same random value will be regenerated. | ||
* Randomness is generated using Flow’s **on-chain `revertibleRandom`**, producing pseudorandom values tied to block and script execution. | ||
briandoyle81 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Values are **deterministic**: The values returned for identical calls within the same block will be identical. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is described here in determinism, so I moved the "deterministic" note here |
||
* If `count ` is larger than one, the returned values are disctinct. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added this so that developers don't think determinism means all
tarakby marked this conversation as resolved.
Show resolved
Hide resolved
tarakby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* This hook is designed for simple use cases that don't require unpredictability, such as randomized UIs. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commit-reveal solves the reversibility issue, but here in the script nothing is reversible so commit-reveal doesn't add any advantage. The main thing developers should be aware of is that the block random source in the lib is publicly known (since this is script-based). There is nothing wrong with that in many applications like the example mentioned here (UIs) |
||
Since the hook uses script executions on existing blocks, Flow's randon source is already public and the randoms are predictable. | ||
briandoyle81 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* For **more advanced use cases** that **do** require on-chain randomness logic via transactions, Flow provides built-in support using Cadence's `revertibleRandom` and [commit-reveal scheme]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The more advanced cases are the ones with the logic fully on-chain via transactions (not scripts). This is where randomness is unpredictable, and reversibility can or cannot be an issue, so I added the mention of transactions here. Both "reversibleRandom" and "commit-reveal" work in that case depending on the app. |
||
|
||
--- | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are no transactions in this case, it's all script based (under the hood, this makes a difference in how randomness works).