Ryan
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# 使用 Sui Move Random 這次要來學習使用 sui::random 內的方法 並產生隨機 1~6 的骰子數字 ```javascript= /// Module: dice_demo module dice_demo::dice_demo { use sui::random::{Self, Random}; // 骰子的物件,是一個 Shared Object public struct Dice has key, store { id: UID, value: u8 } // 部署合約時,初始化一個骰子物件,裡面value給0 // 並且變成一個Shared Object fun init(ctx: &mut sui::tx_context::TxContext) { let uid = object::new(ctx); let dice = Dice { id:uid, value:0 }; transfer::share_object(dice); } // 擲骰子,傳入參數為 // 1. Random物件(sui在devnet提供的0x8) // 2. Shared Object Dice 骰子物件 entry fun roll_dice(r: &Random, dice: &mut Dice, ctx: &mut TxContext) { // 建立一個新的 generator let mut generator = random::new_generator(r, ctx); // 產生一個 1~6 範圍的隨機數,並回傳u8值 let random_num = random::generate_u8_in_range(&mut generator, 1, 6); // 把隨機數存入 Shared Object Dice 骰子物件 dice.value = random_num; } } ``` 部署合約 ```javascript PS D:\vscode\SideProject\sui-contract\dice_demo> sui client publish --gas-budget 800000000 --skip-dependency-verification --skip-fetch-latest-git-deps INCLUDING DEPENDENCY Sui INCLUDING DEPENDENCY MoveStdlib BUILDING dice_demo Skipping dependency verification Transaction Digest: 6KyFoGFnbYAPc1iX2stMWWqdKeh2RUhcYMzHTPJrEFw6 ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Transaction Data │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Sender: 0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11 │ │ Gas Owner: 0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11 │ │ Gas Budget: 800000000 MIST │ │ Gas Price: 1000 MIST │ │ Gas Payment: │ │ ┌── │ │ │ ID: 0x4dbc46608947b4afa8cd83c6585b1b19493e44995ab594622fa9ec2d93f63d38 │ │ │ Version: 1243881 │ │ │ Digest: 7mHpfe728w7vGVrPdYn6TM3Q1VGbAyCoKA45wE2NCSpt │ │ └── │ │ │ │ Transaction Kind: Programmable │ │ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ │ │ Input Objects │ │ │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ │ │ 0 Pure Arg: Type: address, Value: "0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11" │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ ╭─────────────────────────────────────────────────────────────────────────╮ │ │ │ Commands │ │ │ ├─────────────────────────────────────────────────────────────────────────┤ │ │ │ 0 Publish: │ │ │ │ ┌ │ │ │ │ │ Dependencies: │ │ │ │ │ 0x0000000000000000000000000000000000000000000000000000000000000001 │ │ │ │ │ 0x0000000000000000000000000000000000000000000000000000000000000002 │ │ │ │ └ │ │ │ │ │ │ │ │ 1 TransferObjects: │ │ │ │ ┌ │ │ │ │ │ Arguments: │ │ │ │ │ Result 0 │ │ │ │ │ Address: Input 0 │ │ │ │ └ │ │ │ ╰─────────────────────────────────────────────────────────────────────────╯ │ │ │ │ Signatures: │ │ BTuMDk9PxbOvLr71vmuGojdu7YRmKdHeysAHutCpnMohPRbaeR5jLgzWhGcfzbNJJ0yafl6PlTr9PgiR6L8ZDA== │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Transaction Effects │ ├───────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Digest: 6KyFoGFnbYAPc1iX2stMWWqdKeh2RUhcYMzHTPJrEFw6 │ │ Status: Success │ │ Executed Epoch: 63 │ │ │ │ Created Objects: │ │ ┌── │ │ │ ID: 0x31599f857ee6721afa26ece8ab992ba51af7c732390900d3a4834908606be223 │ │ │ Owner: Immutable │ │ │ Version: 1 │ │ │ Digest: 84bpYz8rofM4qcqMGek8VZXsTfEWThqbUKnSWsNZh6w │ │ └── │ │ ┌── │ │ │ ID: 0x9a1586f13af7fc4af8cb5978b12b769c8a260cf9409cf6c3d76761108adef4fe │ │ │ Owner: Shared │ │ │ Version: 1243882 │ │ │ Digest: 68WWVvzdRhkzmao5DuttW1GeSeYKvqr71DtXSX6Ktvdy │ │ └── │ │ ┌── │ │ │ ID: 0xf469dd79f0fb049d9afe779c53f8113f7c240998d68978255297d0a334f67cab │ │ │ Owner: Account Address ( 0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11 ) │ │ │ Version: 1243882 │ │ │ Digest: 5mU1MfGYnR9pUD5rqjz97frDWQ6esXWhBEE8EPGn4jxt │ │ └── │ │ Mutated Objects: │ │ ┌── │ │ │ ID: 0x4dbc46608947b4afa8cd83c6585b1b19493e44995ab594622fa9ec2d93f63d38 │ │ │ Owner: Account Address ( 0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11 ) │ │ │ Version: 1243882 │ │ │ Digest: 3Kh8KGjQ8bsVMpPHRgKHChLvR7M4AEKaKhpfveCTn3Ce │ │ └── │ │ Gas Object: │ │ ┌── │ │ │ ID: 0x4dbc46608947b4afa8cd83c6585b1b19493e44995ab594622fa9ec2d93f63d38 │ │ │ Owner: Account Address ( 0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11 ) │ │ │ Version: 1243882 │ │ │ Digest: 3Kh8KGjQ8bsVMpPHRgKHChLvR7M4AEKaKhpfveCTn3Ce │ │ └── │ │ Gas Cost Summary: │ │ Storage Cost: 9370800 MIST │ │ Computation Cost: 1000000 MIST │ │ Storage Rebate: 978120 MIST │ │ Non-refundable Storage Fee: 9880 MIST │ │ │ │ Transaction Dependencies: │ │ 4F2hCrGNo7j2GNxBFDnsGv5TtyCBc3RCethoLz6k5QN3 │ │ DmLyNauSFrv3F7FV2JgXQmwKRE26wjMrGFipcyKe89G1 │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────╮ │ No transaction block events │ ╰─────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Object Changes │ ├─────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Created Objects: │ │ ┌── │ │ │ ObjectID: 0x9a1586f13af7fc4af8cb5978b12b769c8a260cf9409cf6c3d76761108adef4fe │ │ │ Sender: 0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11 │ │ │ Owner: Shared │ │ │ ObjectType: 0x31599f857ee6721afa26ece8ab992ba51af7c732390900d3a4834908606be223::dice_demo::Dice │ │ │ Version: 1243882 │ │ │ Digest: 68WWVvzdRhkzmao5DuttW1GeSeYKvqr71DtXSX6Ktvdy │ │ └── │ │ ┌── │ │ │ ObjectID: 0xf469dd79f0fb049d9afe779c53f8113f7c240998d68978255297d0a334f67cab │ │ │ Sender: 0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11 │ │ │ Owner: Account Address ( 0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11 ) │ │ │ ObjectType: 0x2::package::UpgradeCap │ │ │ Version: 1243882 │ │ │ Digest: 5mU1MfGYnR9pUD5rqjz97frDWQ6esXWhBEE8EPGn4jxt │ │ └── │ │ Mutated Objects: │ │ ┌── │ │ │ ObjectID: 0x4dbc46608947b4afa8cd83c6585b1b19493e44995ab594622fa9ec2d93f63d38 │ │ │ Sender: 0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11 │ │ │ Owner: Account Address ( 0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11 ) │ │ │ ObjectType: 0x2::coin::Coin<0x2::sui::SUI> │ │ │ Version: 1243882 │ │ │ Digest: 3Kh8KGjQ8bsVMpPHRgKHChLvR7M4AEKaKhpfveCTn3Ce │ │ └── │ │ Published Objects: │ │ ┌── │ │ │ PackageID: 0x31599f857ee6721afa26ece8ab992ba51af7c732390900d3a4834908606be223 │ │ │ Version: 1 │ │ │ Digest: 84bpYz8rofM4qcqMGek8VZXsTfEWThqbUKnSWsNZh6w │ │ │ Modules: dice_demo │ │ └── │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Balance Changes │ ├───────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ┌── │ │ │ Owner: Account Address ( 0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11 ) │ │ │ CoinType: 0x2::sui::SUI │ │ │ Amount: -9392680 │ │ └── │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` 我們主要看 Object Changes 這是我們的 Shared Object Dice 骰子物件 ```javascript │ ┌── │ │ │ ObjectID: 0x9a1586f13af7fc4af8cb5978b12b769c8a260cf9409cf6c3d76761108adef4fe │ │ │ Sender: 0xe20abce08a16e397ec368979b03bb6323d42605b38c6bd9b6a983c6ebcc45e11 │ │ │ Owner: Shared │ │ │ ObjectType: 0x31599f857ee6721afa26ece8ab992ba51af7c732390900d3a4834908606be223::dice_demo::Dice │ │ │ Version: 1243882 │ │ │ Digest: 68WWVvzdRhkzmao5DuttW1GeSeYKvqr71DtXSX6Ktvdy │ │ └── ``` 這是我們部署的智能合約地址 ```javascript │ Published Objects: │ │ ┌── │ │ │ PackageID: 0x31599f857ee6721afa26ece8ab992ba51af7c732390900d3a4834908606be223 │ │ │ Version: 1 │ │ │ Digest: 84bpYz8rofM4qcqMGek8VZXsTfEWThqbUKnSWsNZh6w │ │ │ Modules: dice_demo │ │ └── ``` 首先我們先看 Shared Object Dice 骰子物件 目前的值 使用 suiscan 來查看 https://suiscan.xyz/devnet/object/0x9a1586f13af7fc4af8cb5978b12b769c8a260cf9409cf6c3d76761108adef4fe ![image](https://hackmd.io/_uploads/rygYbr9WR.png) 可以看出value目前只有初始化給的數字0 接下來去到智能合約位置並使用擲骰子的方法 https://suiscan.xyz/devnet/object/0x31599f857ee6721afa26ece8ab992ba51af7c732390900d3a4834908606be223/contracts 第一個參數需傳入Sui在devnet提供的Random物件 0x8 第二個參數需傳入我們的 Shared Object Dice 骰子物件位置 0x9a1586f13af7fc4af8cb5978b12b769c8a260cf9409cf6c3d76761108adef4fe ![image](https://hackmd.io/_uploads/BkRxGr5-C.png) 接下來我們回去看 Shared Object Dice 骰子物件值有沒有改變 ![image](https://hackmd.io/_uploads/B1vwfB5Z0.png) 發現已經變成 2 了,有興趣的朋友可以多試幾次

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully