📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有161部Youtube影片,追蹤數超過5,590的網紅辰宇力 * Uriel Chen,也在其Youtube影片中提到,Hermès Couvertures Nouvelles Tarot playing cards Set includes 78-card deck, Made in France 愛馬仕塔羅牌 是 法國塔羅牌(Tarot français),主要做為遊戲使用。如想作為占卜使用亦可,前提需很熟悉...
「a deck of cards」的推薦目錄:
- 關於a deck of cards 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於a deck of cards 在 Facebook 的最佳貼文
- 關於a deck of cards 在 Dior Facebook 的最佳解答
- 關於a deck of cards 在 辰宇力 * Uriel Chen Youtube 的精選貼文
- 關於a deck of cards 在 Gobby Hong Youtube 的精選貼文
- 關於a deck of cards 在 肥貓丸 FatCatBall Youtube 的最佳解答
- 關於a deck of cards 在 Deck of cards JAVA - Stack Overflow 的評價
- 關於a deck of cards 在 4 Project 2: Playing Cards | Hands-On Programming with R 的評價
a deck of cards 在 Facebook 的最佳貼文
Steam ออกเครื่องเกมพกพาตัวใหม่ล่าสุดในชื่อว่า Steam Deck ใช้ระบบ SteamOS สามารถเล่นเกมต่าง ๆ ในร้าน Steam ได้ทั้งหมดเลย
-
ตัวเครื่องมีขนาดหน้าจอมาให้ 7 นิ้ว ความละเอียด 1280 x 800 พิกเซลแบบสัมผัสได้ Touchscreen พร้อมทั้ง Trackpad ที่ด้านข้างหน้าจอบริเวณตำแหน่งวางนิ้วโป้ง และปุ่มกดกับก้านโยกครบ ๆ
-
เตรียมวางจำหน่ายเดือนธันวาคมปี 2021 ที่จะถึงนี้ ที่ราคาเริ่มต้น $399 ประมาณ 13,000 บาท สำหรับเวอร์ชันความจุ 64GB ตามด้วยเวอร์ชันความจุเพิ่มขึ้นอีกหน่อย 256GB ราคา $529 ประมาณ 17,300 บาท และเวอร์ชันใหญ่สุด 512GB ที่ราคา $649 ประมาณ 21,200 บาท สองตัวหลังจะได้พื้นที่เก็บข้อมูลแบบ NVMe ด้วย และทุกรุ่นสามารถเพิ่มการ์ด microSD ได้
-
สเปกเครื่อง
• CPU: AMD Zen 2 4c/8t, 2.4-3.5GHz (up to 448 GFlops FP32)
• GPU: 8 RDNA 2 CUs, 1.0-1.6GHz (up to 1.6 TFlops FP32)
• RAM: 16 GB DDR5
• Storage: 64GB, 256GB, 512GB versions; expandable with MicroSD cards
• Display: 7" diagonal, 1280x800 (16:10), 60Hz LCD touchscreen
• Audio: Stereo speakers that "pack a punch," says Valve, 3.5mm stereo jack, dual mics, multichannel USB-C/Bluetooth output
• Controls: Two analog sticks with capacitive touch, D-pad, face buttons, analog triggers, bumpers, assignable grip buttons, "view" and "menu" buttons, gyro
• Trackpads: There's two of them, and Valve says that they have "55% better latency compared to Steam Controller."
• Wireless connectivity: Wi-Fi and Bluetooth
• Wired connectivity: USB-C with DisplayPort 1.4 Alt-mode support; up to 8K @60Hz or 4K @120Hz, USB 3.2 Gen 2
• Battery: 40Whr, "2-8 hours of gameplay"
• Size: 11.7" x 4.6" x 1.8" (298mm x 117mm x 49mm)
• Weight: Approximately 1.47 lbs (669 grams)
-
ที่มา https://www.pcgamer.com/steam-deck-handheld-announced/?utm_campaign=socialflow&utm_source=facebook.com&utm_medium=social&fbclid=IwAR3SIisQk2_B3YRtjQKl1EAb2x5bW4bgwPs0KgQiobBLw9fQjmjjOjH-pps
By RecCaz
a deck of cards 在 Dior Facebook 的最佳解答
Discover the new capsule collection from men's Winter 2021 collection launching in boutiques and on.dior.com/kennyscharf-capsule starting July 2, a celebration of Kenny Scharf's irreverent aesthetic that continues the creative dialogue between Kim Jones and the American artist. Ace, king and queen of hearts card symbols (an allusion to Monsieur Dior's fondness for playing) have been reinterpreted and mixed with the iconic 'Dior Oblique' as bandana prints accompanied by individual motifs on a range of contemporary clothing and accessories. In addition, an exceptional numbered box contains a deck of playing cards featuring the collection's special imagery.
© Video: Martin Neumann and Julien & Quentin
Photo: Adrien Toubiana
Partnership done in collaboration with Artestar, a global licensing agency and creative consultancy representing high-profile artists, photographers, designers and creatives.
a deck of cards 在 辰宇力 * Uriel Chen Youtube 的精選貼文
Hermès Couvertures Nouvelles Tarot playing cards
Set includes 78-card deck, Made in France
愛馬仕塔羅牌 是 法國塔羅牌(Tarot français),主要做為遊戲使用。如想作為占卜使用亦可,前提需很熟悉每張牌對應的偉特塔羅牌。
關於法國塔羅牌:https://zh.wikipedia.org/wiki/%E6%B3%95%E5%9C%8B%E5%A1%94%E7%BE%85%E7%89%8C
關聯網站:
星辰宇宙騎士團:https://www.facebook.com/groups/GalaxyKnights/
辰宇力官方Instagram:https://instagram.com/uziastro/
辰宇力官方部落格(Wordpress/简体中文) :http://UziAstro.wordpress.com/
辰宇力官方部落格 (方格子/繁體中文):https://vocus.cc/user/@uziastro
✨ 辰宇力老師,時尚圈御用占星師,精通星座與塔羅。師承星星王子,以準確透徹的星象分析與預測,以及犀利洞察的塔羅解讀聞名。現為東森新聞雲、國際時尚雜誌 InStyle 時尚泉 與 自由時報 的星座專欄作家。偶而會在電視節目或採訪中出現,也曾與樂天市場、安麗、博士倫...等知名廠商聯名合作。
服務項目:https://www.facebook.com/pg/UziAstro/services/
聯繫方式:直接在粉絲頁私訊,或是 email: uziastro@gmail.com
#星座 #運勢 #辰宇力 #PODCAST #台灣 #華文 #人生相談 #諮詢
BGM:
Spring in my Step
End of the Rainbow - Quincas Moreira
Post - Rick Steel
A Brand New Start - TrackTribe
Yellow Rose of Berkeley - Rondo Brothers
.
片頭/片尾動畫: Liangyi Lin
a deck of cards 在 Gobby Hong Youtube 的精選貼文
繼續開箱,自購最愛手袋品牌 Dagne Dover、神諭卡、有機香薰精油跟南非有機護膚品esse!來自iHerb, Book Depository及本地瑜珈服小店UtopiaOOTD。我地一齊黎開箱囉!
❤️ PRODUCTS MENTIONED 提及產品 : ❤️
UtopiaOOTD
—— —— —— —— ——
UtopiaOOTD IG
• https://www.instagram.com/utopiaootd/
Glamour off shoulder tank
• https://utopiaootd.com/index.php/product/glamour-off-shoulder-tank/
瑜珈專用精油濕紙巾
• https://utopiaootd.com/index.php/product/yogatowelettes/
Palo Santo Hand Rolled Incense Sticks
• https://utopiaootd.com/index.php/product/palo-santo-hand-rolled-incense-sticks/
esse Skincare
—— —— —— —— ——
Repair Oil
• https://www.esseskincare.com/product/repair-oil/
Festive Offer Set (Normal Combination Skin)
• https://www.esseskincare.com/festive-offer-1/
iHerb
—— —— —— —— ——
Now Foods - Organic Essential Oils, Spearmint
• https://iherb.co/HWDZAHu
Derma E - Deep Pore Acne Scrub, 2% Salicylic Acid & Anti-Blemish Complex
• https://iherb.co/Ps1TamP
Aura Cacia - Organic Tea Tree
• https://iherb.co/3uDcieA
Aura Cacia - Organic Lemongrass
• https://iherb.co/WJ197A3
Aura Cacia - Organic Myrrth
• https://iherb.co/HnfRoE1
Aura Cacia - Organic Ylang Ylang III
• https://iherb.co/YMBSCdQ
Bookdepositary
—— —— —— —— ——
The Stone Crystals Deck : 78 Crystals to Energize Your Life
• https://www.bookdepository.com/Stone-Crystals-Deck-Andrew-Smart/9781452173283?utm_source=SV-Body&utm_medium=email-Service&utm_term=Book_title&utm_content=order-details&utm_campaign=Order-dispatch
The Sacred Self-Care Oracle : A 55-Card Deck and Guidebook
• https://www.bookdepository.com/Sacred-Self-Care-Oracle-Jillian-Pyle/9781401958695?utm_source=SV-Body&utm_medium=email-Service&utm_term=Book_title&utm_content=order-details&utm_campaign=Order-dispatch
The Illuminated Tarot : 53 Cards for Divination & Gameplay
• https://www.bookdepository.com/Illuminated-Tarot-Caitlin-Keegan/9780451496836?utm_source=SV-Body&utm_medium=email-Service&utm_term=Book_title&utm_content=order-details&utm_campaign=Order-dispatch
Affirmators! Tarot Deck
• https://www.bookdepository.com/Affirmators-Tarot-Deck/9781683491873?utm_source=SV-Body&utm_medium=email-Service&utm_term=Book_title&utm_content=order-details&utm_campaign=Order-dispatch
Dagne Dover
—— —— —— —— ——
Dagne Dover - Landon Carryall Bag in Onyx in XS size
• https://www.dagnedover.com/collections/the-landon-carryall
* * * * *
Dagne Dover官網購物
新客户消費滿USD$25以上9折優惠
https://share.dagnedover.com/x/cfVGwM
* * * * *
高比網誌:https://gobbyhong.com/
護膚排行榜:https://gobbyhong.com/skincare-ranking/
美妝排行榜:https://gobbyhong.com/makeup-ranking/
其他排行榜:https://gobbyhong.com/other_ranking/
===== ===== ===== =====
Dagne Dover官網購物
新客户9折優惠
使用以下連結 - 消費滿USD$25以上再有9折
https://share.dagnedover.com/x/beFMWO
===== ===== ===== =====
Yesstyle購物
購物平少少
Referral code:GOBBYYES
Yesstyle : https://ys.style/a6Id0GURT9
===== ===== ===== =====
iHerb購物
新舊用户iHerb購物全單95折
Referral code:PAQ598
Referral Link:https://iherb.co/cgoCEP4Y
===== ===== ===== =====
Lookfantastic購物
優惠1 - *Friends Referral
消費滿HKD$400減HKD$100
專用連結 - https://tidd.ly/3fYWlPN
優惠2 - *購物75折
Referral code:GOBBY
專用連結 - https://tidd.ly/2I3cJlG
(部份品牌除外)
===== ===== ===== =====
Everyday Minerals [ Referral Programme ]
經以下連結全單8折
http://937everydaymineral.refr.cc/gobbyhong
===== ===== ===== =====
熱門Playlist:
• 「5件最值得 Monthly 5 Best find」
https://www.youtube.com/playlist?list=PL6wamDBsOr3qVIA2oO-UqQ7L-SdmIByfY
• 「大評比 Review」
https://www.youtube.com/playlist?list=PL6wamDBsOr3os1WRIc0OgPtZFjJNsSD7J
• 「遊.記生活 Vlog」
https://www.youtube.com/playlist?list=PL6wamDBsOr3rjWE4QJSh2azqPAR_JVIxq
• 「煮.食 Cooking 」
https://www.youtube.com/playlist?list=PLBAB1D8260E93EA4C
• 「用清清、開箱購物樂 Empties & Haul 」
https://www.youtube.com/playlist?list=PLC28462D11F9C5E73
——— ——— ——— ——— ———
有朋友會幫的打字幕嗎?歡迎捐獻字幕!有心者我會把名字放在info box中以表感謝! 記得開首打左自己名先呀... (e.g. 字幕提供xxx字幕組)
https://www.youtube.com/timedtext_cs_panel?c=UCngc-JNlTr_oewK_riWwj8A&tab=2
WELCOME to submit subtitles to this video!! You would be credited and appreciated in the info box~ Remember to type your name from the very beginning of the subtitles (e.g. Subtitle by xxx) Thank you!!
? Like and Subscribe
Youtube ➡️ http://www.youtube.com/gobbyhong
? Follow me
FB ➡️ http://www.facebook.com/gobbyhappylife
IG ➡️ http://instagram.com/gobihong
a deck of cards 在 肥貓丸 FatCatBall Youtube 的最佳解答
OTK:05:04、08:54
BGM:https://youtu.be/lKMqwRv3plI
※本牌組勝率不高,請斟酌使用
加入肥貓丸頻道會員,享專屬會員徽章:
https://www.youtube.com/channel/UCbr1TwV0Tk7LeQ5Yzi0vRxA/join
惡魔劫奪者
Fel Reaver
每當對手出一張牌,移除你牌堆最上面的三張牌
Whenever your opponent plays a card, remove the top 3 cards of your deck.
希拉斯‧暗月
Silas Darkmoon
戰吼:選擇一個方向,旋轉全部手下
Battlecry: Choose a direction to rotate all minions.
『八爪巨怪』歐托薩利
Octosari
死亡之聲:抽8張牌
Deathrattle: Draw 8 cards.
※本牌組勝率不高,請斟酌使用
附上牌組:
職業:德魯伊
規則:開放
2x (0) 啟動
2x (1) 自然化
2x (2) 憤怒
2x (3) 兇猛狂嚎
1x (3) 布萊恩‧銅鬚
2x (3) 泥沼光束
2x (3) 翠玉之花
1x (4) 劇毒種子
1x (4) 多汁的靈心瓜
2x (4) 尋找出路
1x (4) 揮擊
2x (4) 蔓生術
1x (5) 惡魔劫奪者
2x (5) 星殞術
1x (6) 滋補術
1x (7) 『疫病蟲王』瑪法里恩
1x (7) 希拉斯‧暗月
1x (7) 洪流
1x (8) 『八爪巨怪』歐托薩利
1x (10) 『遺忘君王』坤恩
1x (10) 艾維娜
AAEBAbSKAwxAX4oOvg/sFYUX4LsCmdMCjPsC26UDg6cDyOEDCVbpAf4BxAbLvAKe0gK/8gLougPuugMA
#爐石OTK
a deck of cards 在 4 Project 2: Playing Cards | Hands-On Programming with R 的推薦與評價
Best of all, the deck will remember which cards have been dealt–just like a real deck. You can use the deck to play card games, tell fortunes, and test card- ... ... <看更多>
a deck of cards 在 Deck of cards JAVA - Stack Overflow 的推薦與評價
... <看更多>