📜 [專欄新文章] Gas Efficient Card Drawing in Solidity
✍️ Ping Chen
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium
Assign random numbers as the index of newly minted NFTs
Scenario
The fun of generative art NFT projects depends on randomness. The industry standard is “blind box”, where both the images’ serial number and the NFTs’ index are predetermined but will be shifted randomly when the selling period ends. (They call it “reveal”) This approach effectively solves the randomness issue. However, it also requires buyers to wait until the campaign terminates. What if buyers want to know the exact card right away? We’ll need a reliable onchain card drawing solution.
The creator of Astrogator🐊 isn’t a fan of blind boxes; instead, it thinks unpacking cards right after purchase is more interesting.
Spec
When initializing this NFT contract, the creator will determine the total supply of it. And there will be an iterable function that is randomly picking a number from the remaining pool. The number must be in range and must not collide with any existing ones.
Our top priority is accessibility/gas efficiency. Given that gas cost on Ethereum is damn high nowadays, we need an elegant algorithm to control gas expanse at an acceptable range.
Achieving robust randomness isn’t the primary goal here. We assume there’s no strong financial incentive to cheat, so the RNG isn’t specified. Implementers can bring their own source of randomness that they think is good enough.
Implementation
Overview
The implementation is pretty short and straightforward. Imagine there’s an array that contains all remaining(unsold) cards. When drawIndex() is called, it generates a (uniform) random seed to draw a card from the array, shortens the array, and returns the selected card.
Algorithm
Drawing X cards from a deck with the same X amount of cards is equal to shuffling the deck and dealing them sequentially. It’s not a surprise that our algorithm is similar to random shuffling, and the only difference is turning that classic algo into an interactive version.
A typical random shuffle looks like this: for an array with N elements, you randomly pick a number i in (0,N), swap array[0] and array[i], then choose another number i in (1,N), swap array[1] and array[i], and so on. Eventually, you’ll get a mathematically random array in O(N) time.
So, the concept of our random card dealing is the same. When a user mints a new card, the smart contract picks a number in the array as NFT index, then grabs a number from the tail to fill the vacancy, in order to keep the array continuous.
Tweak
Furthermore, as long as the space of the NFT index is known, we don’t need to declare/initialize an array(which is super gas-intensive). Instead, assume there’s such an array that the n-th element is n, we don’t actually initialize it (so it is an array only contains “0”) until the rule is broken.
For the convenience of explanation, let’s call that mapping cache. If cache[i] is empty, it should be interpreted as i instead of 0. On the other hand, when a number is chosen and used, we’ll need to fill it up with another unused number. An intuitive method is to pick a number from the end of the array, since the length of the array is going to decrease by 1.
By doing so, the gas cost in the worst-case scenario is bound to be constant.
Performance and limitation
Comparing with the normal ascending index NFT minting, our random NFT implementation requires two extra SSTORE and one extra SLOAD, which cost 12600 ~ 27600 (5000+20000+2600) excess gas per token minted.
Theoretically, any instantly generated onchain random number is vulnerable. We can restrict contract interaction to mitigate risk. The mitigation is far from perfect, but it is the tradeoff that we have to accept.
ping.eth
Gas Efficient Card Drawing in Solidity was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.
👏 歡迎轉載分享鼓掌
同時也有100部Youtube影片,追蹤數超過296的網紅Peeguu,也在其Youtube影片中提到,► WATCH ME LIVE: https://www.twitch.tv/peeguutv ► Follow me on Twitter: https://www.twitter.com/peeguutv ► Follow me on Instagram: https://www.instag...
「random pick」的推薦目錄:
- 關於random pick 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於random pick 在 HYST shop Facebook 的精選貼文
- 關於random pick 在 Monster Taipei Facebook 的最佳解答
- 關於random pick 在 Peeguu Youtube 的最佳解答
- 關於random pick 在 Wenwen Stokes Youtube 的精選貼文
- 關於random pick 在 紙片模型 Youtube 的最佳貼文
- 關於random pick 在 Picking Non-duplicate Random Numbers using JavaScript 的評價
- 關於random pick 在 Random Pick (OpenVINO Grasp Detection) 的評價
- 關於random pick 在 Random selection of polygon but with certain value - GIS ... 的評價
random pick 在 HYST shop Facebook 的精選貼文
random pick from our @prototyp_formula customer .
thank you guys for support 🤝🤝🤝
hope more style show up!!!
www.hyst-shop.com
random pick 在 Monster Taipei Facebook 的最佳解答
MONSTER TAIPEI INTERNATIONAL LOTTERY
全球網路抽選活動
Dino Gangster 恐龍黑幫 腕龍酒保 豪斯.巴克利 - 標準情人配色
「Dino Gangster 恐龍黑幫」是由台灣設計師 Spawnmax 米腸駿筆下的原創作品,以恐龍未滅絕的世代為創作題材,進而展開一連串熱血有趣的恐龍黑幫文化故事。
一年一度的七夕情人節又要到了,相較於之前的怪力豪斯原色版,本次恐龍黑幫推出腕龍酒保 豪斯‧巴克利的標準情人配色,外號是「怪力豪斯」,小清新的文青風格,一改重現江湖氣的對比配色,以粉紅豹紋搭配牛仔褲刷白,還帶著可愛的電子錶,準備來一場牛郎織女般的邂逅。
故事背景:
買完花的豪斯,來到約定的巷口,看到兩個單身狗小盜龍在騷擾等他的新女友
梁龍–“梁靖茹”,瞬間勇氣爆棚來一個箭步,握著花束的左拳一揮!
兩隻衰仔就瞬間被打飛到了幾十丈外,但花束也毀了,形成漫天飛舞的紅花瓣。
豪斯一個華麗轉身,輕聲說道:「沒事吧?寶貝」,女友好氣又好笑地罵著豪斯要他賠一束花給她……
但豪斯早有準備,話鋒一轉:「妳看 現在都幾點了?」
女友一看他的手錶說:「你剛剛打架打壞了嗎? 現在怎麼是 13:14 還5月20咧?!」
豪斯說:「妳再唸一次」
靖茹:「吼呦,討M啦 ~///~」
此次 MONSTER TAIPEI 獨家開放抽選14隻,喜愛恐龍黑幫系列作品的朋友,千萬不要錯過了!
Dino Gangster 恐龍黑幫 品牌介紹:
本該滅絕的地球霸主恐龍,躲過了隕石天災攻擊,無天敵的它們肆無忌憚的持續繁衍著,數千年逐漸演化為人型,也發展出自我流行文化,成立幫派互相爭奪地盤。
恐龍牙齒做為品牌標誌,表示恐龍激烈衝突感,目前出品了四款角色,包含三角龍老大 腹黑-羅伯 . 維克多、暴龍拳王 拳帝-麥可 . 雷克斯、怪力酒保腕龍-豪斯 . 巴克利、劍龍清道夫-漢諾克,富有特色原創設計,不設限的持續發展出更多熱血有趣的故事。
設計師介紹:
台灣原創設計師-Spawnmax 米腸駿,擔任遊戲公司人物及服裝主設計,還是一名插畫家,目前在玩具公司任職,於2017年推出原創故事「小飛腸」系列軟膠,直到2019年推出「恐龍黑幫」系列軟膠,創作題材不斷推陳出新,期待未來會帶給大家更多不一樣的作品。
Facebook: Dino Gangster 恐龍黑幫
https://www.facebook.com/DinoGangsters/
抽選販售商品:
Dino Gangster 恐龍黑幫 腕龍酒保 豪斯.巴克利 - 標準情人配色
尺寸:全高約 29cm (H)
材質:軟膠 soft vinyl、施華洛世奇水晶貼鑽、乾燥花束
售價:TWD.4980/pc
※注意事項:乾燥花束為國外進口之天然色滿天星,自然擺放可維持一年多左右,如有損傷為自然耗損,將不再補送,敬請見諒。
※ MONSTER TAIPEI 獨家開放抽選14隻,頭卡均附上設計師親簽及限量編號。
抽選表單填寫時間:
2021/08/13 (五) 15:00 ~ 2021/08/14 (六) 20:00
抽選表單連結:
https://forms.gle/aEf9P7e1TcLTt2r98
販售規則:
1. 此商品採線上抽選方式販售,欲參加抽選的朋友請填寫 Google 表單,需登入 Google 帳號,一人一個帳號限填寫一次,如有重複填寫資料者或資料填寫不齊全者將直接取消抽選資格。
2.請於表單開放時間內填寫,逾時不候。
3.抽選將會使用電腦亂數程式隨機抽選,抽選結果將於 2021/08/15 (日) 當天 21:00 前以簡訊及 e-mail 通知中選者,未中選者不另行通知。
4.中選者需於收到中選通知後三日內 2021/08/18 (三) 結束前完成付款,如中選者未在時間內完成交易將直接取消購買資格並列入永久黑名單,請務必確認是否能在規定時間內付款再參與抽選活動。
5.中選者購買方式選擇
(1) 台灣地區中選者
a. Monster Taipei實體門市取貨付款 (現金/刷卡) 。
b. 提供上海商銀帳戶匯款郵寄。 (運費$80)
(2) 海外地區中選者
僅提供 PayPal 付款 (需另加 5% PayPal 手續費),依所在地區的不同,運費金額將會另行估算,隨中選信通知附上運費金額。
6.參與抽選的朋友如有中選,請遵守以下規定
(1) 選擇至 Monster Taipei 實體門市自取:請務必於指定時間內攜帶身份證件至門市取貨付款,非本人無法領取,不接受親朋好友代領等行為。
(2) 選擇郵寄:請務必於指定時間內付款,抽選表單上填寫的收件人及地址無法更改,欲更改者視同放棄購買資格。
7.申請抽選將視為皆已同意以上規則,Monster Taipei 保有最終販售及修改之權利。
Monster Taipei 台北怪獸國際有限公司
International Lottery Sale Item:
Dino Gangster Bartender Brachiosaurus House Barkley – Valentine’s Day Ver.
Size: 29cm (H)
Material:Soft Vinyl、Swarovski Rhinestones、Dry Bouquet
Price:TWD.4980/pc
NOTE : The flowers attached are natural color Baby's Breath, imported from abroad, which can last for about a year. All damages are regarded as natural wear and tear, will not sent spare parts, sorry for the inconvenient.
※MONSTER TAIPEI exclusive lottory for 14 pieces, the head card are attached with the designer's signature and limited number.
Opening hours for lottery:
2021/08/13 (FRI) 15:00 ~ 2021/08/14 (SAT) 20:00
Google form link for lottery:
https://forms.gle/aEf9P7e1TcLTt2r98
Sales rules:
1. This item is sold by global online lottery. Friends who want to participate in the lottery, please fill out the Google form by your Google account. Each account is limited to one time only. If you fill in the information repeatedly or fill in the information incompletely, you will be directly disqualified from the lottery. .
2. Please fill in the form within the opening hours, overtime filing will not be accepted.
3. The lottery will be randomly selected using a computer random number program. The results of the lottery will be notified on 2021/08/15(SUN) by SMS and e-mail before 21:00. Those who lost the chance will not be notified.
4. Winners of the lottery need to complete the payment within three days 2021/08/18(WED) after receiving the notification. If they didn't complete the payment within the time limit, the purchase qualification will be directly cancelled and be included in the permanent blacklist. Please confirm whether able to pay within the specified time before participating in the lottery.
5. Way of purchase
(1) Winners in Taiwan :
a. Pay on site and pick up in Monster Taipei store.
b. Delivery inside Taiwan and provide Shanghai Commercial Bank Account to remit. (TWD.80 for shipping)
(2) Winners from Overseas :
Only PayPal payment is available (additional 5% PayPal handling fee is required). Depending on the region, the shipping amount will be estimated separately, and the shipping amount will be attached to the notification.
6. The recipient and address on the lottery form cannot be changed, and those who wish to change will be regard as giving up the qualification.
7. Application for lottery will be deemed to have agreed to the above rules, Monster Taipei reserves the right to final sales and modification.
MONSTER TAIPEI INTERNATIONAL INC.
random pick 在 Peeguu Youtube 的最佳解答
► WATCH ME LIVE: https://www.twitch.tv/peeguutv
► Follow me on Twitter: https://www.twitter.com/peeguutv
► Follow me on Instagram: https://www.instagram.com/peeguu_
Today, we decided to walk around Xi Men Ding in Taipei and ask random strangers if they will be willing to each Hai Di Lao with me... the catch is... I GOTTA USE PICK-UP LINES given by Twitch Chat.
![post-title](https://i.ytimg.com/vi/Lf4WFHbrLL8/hqdefault.jpg)
random pick 在 Wenwen Stokes Youtube 的精選貼文
Hey guys!
Thought i'd pick up the camera to vlog some random bits the other day. Conrad's Water Rower finally arrived, it was my Christmas present to him as i knew he had done some research and was eyeing it. It should honestly be a motivator for me to get on too! haha. Also revealing something different from Fendi and the sickest pair of white boots! Also hope you enjoy seeing some of the cringe outfits from when i was taking outfit photos in high school! Some of them are honestly soooo embarrassing. :P
I get comments sometimes asking me to share more cooking recipes, I cant stress enough, i really am not someone that spends a lot of time in the kitchen so my recipes are minimal and super easy ahahaah, but since some of you seem to enjoy the cooking, ill do what i can. :P
Check out my instagram @wenwenstokes
Items mentioned in video:
Waterrower: https://bit.ly/39JmqRa
Fendi DIY baguette not online
Eytys white boots: https://bit.ly/3trzenh
![post-title](https://i.ytimg.com/vi/t2_GEmWbUgM/hqdefault.jpg)
random pick 在 紙片模型 Youtube 的最佳貼文
**如果 Minecraft 是一款 MMORPG 遊戲,會是什麼樣的感覺?**
- 整個地圖根據等級,被劃分成好幾個地區。我們得在新手村不斷打怪、升級、換裝備,才有機會向外探索;
- 變強方式也變得完全不一樣,有體力、力量、智力、魔力、敏捷、耐力六大屬性;
- 以及堪比星空之多的天賦樹。看你是要當玻璃大砲,還是養成血量坦克,全都掌握在你的手裡。
過往的楓之谷、暗黑破壞神、RO 就是這類遊戲的代表。然而隨著環境的變遷,這些遊戲早已成為了時代的眼淚。為了重回過去的渴望,麥塊模組,便成為了一個最好的工具。
這次紙片找來了 30 個冒險向 RPG 模組。數量比以往還多。仔細挑,隨便選。
這裡總有一款屬於你的模組。
—
**Minecraft 版 MMORPG 模組列表**
1. Mine and Slash 挖礦與砍殺 - 1.15、1.12 (0:59)
https://www.curseforge.com/minecraft/mc-mods/mine-and-slash-reloaded
2. Scaling Health 動態難度 - 1.15、1.12 (1:29)
https://www.curseforge.com/minecraft/mc-mods/scaling-health
3. Rotten Creatures 腐朽生物 - 1.15 (2:10)
https://www.curseforge.com/minecraft/mc-mods/rotten-creatures
4. Primitive Mobs 原始生物 - 1.12 (2:53)
https://www.curseforge.com/minecraft/mc-mods/primitive-mobs
5. Mowzie's Mobs 莫西的傳說生物 - 1.12 (3:14)
https://www.curseforge.com/minecraft/mc-mods/mowzies-mobs
6. Fish's Undead Rising 亡靈怪物 / 亡靈生物 - 1.12 (3:46)
https://www.curseforge.com/minecraft/mc-mods/fishs-undead-rising
7. Animalium 更多動物 - 1.15、1.12 (4:14)
https://www.curseforge.com/minecraft/mc-mods/animalium
8. Doggy Talent 天才小狗/養狗模組 - 1.15、1.12 (4:30)
https://www.curseforge.com/minecraft/mc-mods/doggy-talents
9. Biomes O' Plenty 更多的生態域 - 1.15、1.12 (4:59)
https://www.curseforge.com/minecraft/mc-mods/biomes-o-plenty
10. Biome Bundle O Plenty 大量的生態域 - 1.12 (5:30)
https://www.curseforge.com/minecraft/mc-mods/biome-bundle-o-plenty
11. WildNature | A Wilder Experience 野生自然 | 野外的體驗 - 1.14、1.12 (6:04)
https://www.curseforge.com/minecraft/mc-mods/wildnature
12. Xaero's World Map 薩伊羅地圖 - 1.15、1.12 (6:30)
https://www.curseforge.com/minecraft/mc-mods/xaeros-world-map
13. Xaero's Minimap 薩伊羅小地圖 - 1.15、1.12 (6:30)
https://www.curseforge.com/minecraft/mc-mods/xaeros-minimap
14. Antique Atlas 古董地圖 - 1.12 (7:01)
https://www.curseforge.com/minecraft/mc-mods/antique-atlas
15. Nature's Compass 生態域羅盤 / 生態域指南針 - 1.15、1.12 (7:23)
https://www.curseforge.com/minecraft/mc-mods/natures-compass
16. Waystones 傳送點 - 1.15 (7:43)
https://www.curseforge.com/minecraft/mc-mods/waystones
17. Sword Blocking Combat 用劍擋 - 1.15 (8:16)
http://bit.ly/32msb1N
18. Electroblob's Wizardry 巫術學 - 1.12 (8:33)
https://www.curseforge.com/minecraft/mc-mods/electroblobs-wizardry
19. Reskillable 熟練(技能)模組 - 1.12 (9:00)
https://www.curseforge.com/minecraft/mc-mods/reskillable
20. ZmodSkills 技能模組 - 1.15 (9:30)
https://www.curseforge.com/minecraft/mc-mods/zmod-new-skills-system
21. Customized Dungeon Loot 自定義戰利品 - 1.12 (10:01)
https://www.curseforge.com/minecraft/mc-mods/customized-dungeon-loot
22. Random Loot Mod 隨機戰利品 - 1.12 (10:27)
https://www.curseforge.com/minecraft/mc-mods/random-loot-mod
23. Neat 血量 - 1.15、1.12 (10:41)
https://www.curseforge.com/minecraft/mc-mods/neat
24. Ama's Damage Indicator 戰鬥數值顯示器 - 1.15 (10:56)
https://www.curseforge.com/minecraft/mc-mods/ama-damage-indicator
p.s 如果想在 1.12 安裝的話,可改用《ToroHealth Damage Indicators 傷害顯示》
https://www.curseforge.com/minecraft/mc-mods/torohealth-damage-indicators
25. Inventory HUD+ (Forge) 更好的戰鬥介面 - 1.15、1.12 (11:10)
https://www.curseforge.com/minecraft/mc-mods/inventory-hud-forge
26. Pick Up Notifier 獲取訊息通知 - 1.15、1.12 (11:29)
https://www.curseforge.com/minecraft/mc-mods/pick-up-notifier
27. Mo' Bends 動作模組 - 1.12 (11:50)
https://www.curseforge.com/minecraft/mc-mods/mo-bends/files
28. Back Tools 背在背上 - 1.15、1.12 (11:59)
https://www.curseforge.com/minecraft/mc-mods/back-tools
29. Dynamic Surroundings 動態環境 - 1.12 (12:11)
https://www.curseforge.com/minecraft/mc-mods/dynamic-surroundings
Q:為什麼只有 29 種,不是說好是 30 嗎?
A:
1. QAQ...原本準備到了 33 種模組,但後來因為版本相容性問題,被踢掉了 4 種。
2. 取個整數比較好看:P
—
常見問題
Q:手機能裝嗎?
A:不行,如果紙片的影片如果沒有特別著明,通常都是電腦上遊玩的 Java 版唷。
Q:想找到完整的版本嗎?
A:進入模組頁面 → Files 分頁 → View All 按鈕 → Game Version。即可找到所有版本。
Q:安裝時遇到錯誤,需要前置模組?
A:有兩種方法解決:
1. 閱讀錯誤訊息,直接 Google 訊息所顯示的模組名稱,下載安裝即可。
2. 進入模組頁面 → Relations 分頁。即可找到關聯模組,有時候會顯示非前置但有相關的。
Q:怎麼安裝模組?
A:
1. 請參考紙片的模組教學影片。大多數人會在安裝 Forge 時出錯,請預先裝 Java 並透過他開啟即可。很多時候都是壓縮軟體關聯了 ".jar" 副檔名,導致電腦新手以為下載成了壓縮檔。
2. 透過 MuiltMC 安裝(大推!)
—
Instagram: http://bit.ly/Paper_IG
Facebook: http://bit.ly/Paper_FB
Discord: http://bit.ly/PaperDiscord
—
► 訂閱我的YouTube頻道吧:http://bit.ly/PAPERsubs
—
錄影程式:Bandicam
聲音處理:Audacity
後製軟體:Adobe Premiere cc
—
如果你想要聯絡我,歡迎透過信箱聯繫。礙於人手不足,回應時間約三至七天,請見諒。
E-mail: mlz85613@gmail.com
![post-title](https://i.ytimg.com/vi/CD5i9EXoTG0/hqdefault.jpg)
random pick 在 Random Pick (OpenVINO Grasp Detection) 的推薦與評價
Random Pick (OpenVINO Grasp Detection)¶. Overview¶. A simple application demonstrating how to pick up objects from clutter scenarios with an industrial robot ... ... <看更多>
random pick 在 Random selection of polygon but with certain value - GIS ... 的推薦與評價
You can select a subset of your data using your attribute column "population" (let's say population > 20.000.000). ... <看更多>
random pick 在 Picking Non-duplicate Random Numbers using JavaScript 的推薦與評價
... <看更多>