📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有26部Youtube影片,追蹤數超過6萬的網紅粒方不插電,也在其Youtube影片中提到,遊戲購買連結: https://www.ruten.com.tw/item/show?22042658513851 歡迎再度來到桌遊秀!這次要來玩的是Among Us太空狼人殺的桌遊版 The Menace Among Us! 我們究竟能不能在達成目標的情況下存活呢? 快來看看吧! Among...
「random card deck」的推薦目錄:
- 關於random card deck 在 Taipei Ethereum Meetup Facebook 的最佳貼文
- 關於random card deck 在 OverBoot Facebook 的最讚貼文
- 關於random card deck 在 愛必 Facebook 的最佳解答
- 關於random card deck 在 粒方不插電 Youtube 的精選貼文
- 關於random card deck 在 粒方不插電 Youtube 的最佳貼文
- 關於random card deck 在 肥貓丸 FatCatBall Youtube 的最讚貼文
- 關於random card deck 在 How to randomly select a card from a deck of cards and not ... 的評價
- 關於random card deck 在 Mamouel/playing-cards: Deck of cards in React ... - GitHub 的評價
- 關於random card deck 在 JavaScript Deck Builder: Build Deck, Draw Random Card from ... 的評價
- 關於random card deck 在 Random Card Deckbuilding Challenge - Intro and Deck Tech 的評價
- 關於random card deck 在 Zoink Games - Card Deck - Lost In Random | Facebook 的評價
- 關於random card deck 在 Drawing integers - Random numbers and simple games 的評價
random card deck 在 OverBoot Facebook 的最讚貼文
ไปกันไหมครับ -0-
Mark the date! ~ ถึงเวลารวมตัวเหล่าโปเกมอนเทรนเนอร์! ในงาน Nx Pokemon TCG x VCG วันอาทิตย์ที่ 24/11/19 ที่ Amarin Plaza (4th fl.) ในงานพบกับการแข่งขันโปเกมอนการ์ดชุดล่าสุด "เทพเวหา" ชิง Nintendo Swtich และ การแข่งขัน VGC โปเกมอน Sword & Shield ทั้งแมตซ์กระชับมิตร และแบบจริงจังชิงรางวัลเช่นกัน!
ตารางงานคร่าวๆ
10.00 น. - เริ่มเปิดบูธ และเปิดลงทะเบียนสำหรับแข่งขันการ์ดเกม
__________________________________
10.30 น. - การแข่งขัน Pokemon TCG ชุดเทพเวหา ในรูปแบบ "Sealed"
- ค่าสมัคร 599 บาท (สำหรับผู้ลงทะเบียนล่วงหน้า) / Walk-in 650 บาท
- ผู้เข้าแข่งขันจะได้รับ Gx Starter Deck ชุดล่าสุดแบบสุ่ม + Booster Pack A x3 + Booxster Pack B x3
- ใช้การ์ดที่ได้มาทั้งหมดในการจัด 1 Deck ภายในงานจะมี Energy Station สำหรับเติมพลังงานพื้นฐาน เข้าไปใน Deck หากต้องการ
- รูปแบบการแข่งขัน Swiss Round ตัด Top 8 แบบ Best of One
รางวัลการแข่งขัน
1st - Nintendo Switch Lite (Pokemon ed.)
2nd - 1 Booxster Box
3rd - 4th - 20 ซอง
5th - 8th - 6 ซอง
9th - 16th - 2 ซอง
*รางวัลแจกเป็น Booster Pack ชุดใหม่ "เทพเวหา" ทั้งหมด
__________________________________
ระหว่างงานมีบูธสินค้าสำหรับ TCG มากมาย, Video Game, ตุ๊กตาลิขสิทธิ์แท้, และอื่นๆอีกมากมาย พร้อมโปรโมชั่นพิเศษ ตลอดงาน
__________________________________
15.00 น. - Pokeon VGC Workshop by Penguin Hut x OverBoot และเปิดลงทะเบียนการแข่งขัน Video Game Championship กับโปเกมอนภาคล่าสุด Sword & Shield
15.30 น. - งานแข่งขัน Pokemon VGC โดยจะมีการแบ่งสายการแข่งขัน รายละเอียดเพิ่มเติมโปรดติดตามเร็วๆนี้!
งานจะ Run ถึงประมาณ 20.30 น. โดยประมาณ และมี After Party ต่อด้วยนะครับ
__________________________________
สถานที่จัดงาน: https://goo.gl/maps/vRsa6tNcZrzfcgwx8
เปิด Preregis แล้ววันนี้ และหากมีข้อสงสัยเพิ่มเติมสามารถสอบถามได้เลย ...แล้วเจอกันวันอาทิตย์ที่ 24/11/19 งานนี้ห้ามพลาดเด็ดขาดครับ ^^!
Mark the date! ~ time to reunite the Pokémon trainers! At NX Pokemon TCG X Vcg Sunday 24/11/19 at Amarin Plaza (4TH FL. ) at the latest Pokémon card match "Thep Weha" win Nintendo swtich and vgc pokémon sword & Shield. Both friendly and serious match!
Roughly schedule
10.00 pm - booth starts and registration is open for game card competition.
__________________________________
10.30 pm - Pokemon TCG Competition. Great dress in "sealed" form.
- application fee 599 baht (for pre-registered) / walk-in 650 baht
- contestants will receive the latest gx starter deck. Random Set + Booster Pack a x3 + Booxster Pack x3
- use all acquired cards to arrange 1 Deck. There will be energy station for basic energy into deck if needed.
- Swiss round match pattern. Top 8 best of one
Competition award
1st - Nintendo Switch Lite (Pokemon ed. )
2nd - 1 Booxster Box
3RD-4th-20 packs
5th-8th-6 Packs
9th-16th-2 Packs
* giveaway prize as a new booster pack. All "Thep Weha"
__________________________________
During the event, there are many TCG Products Booths, video game, Authentic Copyright Dolls, and more with special promotions throughout the event.
__________________________________
15.00 pm - pokeon vgc workshop by Penguin Hut x overboot and registration is open for video game championship with the latest pokemon sword & shield
15.30 pm - Pokemon vgc competition will be divided. More details stay tuned soon!
The event will run until around 20.30 pm. Estimated and after party. Continue.
__________________________________
Venue: https://goo.gl/maps/vRsa6tNcZrzfcgwx8
Preregis is open today and if you have more questions, you can ask us... see you on Sunday 24/11/19 don't miss this event ^^!Translated
random card deck 在 愛必 Facebook 的最佳解答
找到 #天使回應卡 的線上抽卡網站了~(點進去就直接是抽到的卡片囉)🙏✨😇
木星八宮好像很容易挖到寶XD 已更新到抽卡網站整理囉👇
https://www.facebook.com/ibeindeed/photos/a.495843943945671.1073741829.378866122310121/803815783148484/?type=3&theater
#小分享之必要
random card deck 在 粒方不插電 Youtube 的精選貼文
遊戲購買連結: https://www.ruten.com.tw/item/show?22042658513851
歡迎再度來到桌遊秀!這次要來玩的是Among Us太空狼人殺的桌遊版 The Menace Among Us!
我們究竟能不能在達成目標的情況下存活呢? 快來看看吧!
Among Us》是一款多人電子遊戲,由美國]遊戲工作室InnerSloth開發並於2018年6月15日發布。遊戲以太空為主題,玩家將扮演船員(Crewmate)或入侵者(Impostor)之一。船員的目標找出入侵者並完成任務,而入侵者的目標是殺死所有船員而不被發現。雖然遊戲於2018年發布,但鮮有問津,直到2020年因為眾多Twitch實況主和YouTuber遊玩才流行起來。為回應遊戲的熱度,遊戲開發者於2020年8月宣布將開發續作《Among Us 2》,但是一個月後(9月)宣布取消續作的開發,將重點轉移到改進原版遊戲上
The Menace Among Us is a semi-cooperative game of intrigue and survival in deep space. Adrift and powerless, your crippled vessel is bleeding oxygen. As you effect repairs, every breath you take brings you one step closer to death. You must work together to restore power before the air runs out — but hidden among you, as loyal friends and crew members, are imposters who have infiltrated security and continue to sabotage the ship. Their only goal is to avoid detection and kill the crew, by force or by asphyxiation. Can you identify them in time and eliminate the threat? Or will succumb to the menace among us?
The Menace Among Us is a 40 to 60-minute, asymmetrical card game for 4-8 players. Each player chooses an Agenda at random, either a loyal Crew member, a deadly Menace or the Coward, who’ll take any side just to survive. Your Agenda card sets a Team Goal and an Individual Goal, as well as outlines any special abilities and the card composition of your individual 13-card deck. Then, knowing your Agenda and Goals, you choose a Character who you believe will best help you achieve them or mask your true identity. Characters add 7 new cards to your deck, shuffle-building a unique combination of cards, as well as provide you two specialized Above Deck Actions.
In this hidden traitor game, how you play your cards and abilities is far more important than the meta game aspects of accusations and denials. Cards are played face down and shuffled together as “Below Deck Actions.” Here, Menace players secretly sabotage the ship’s systems and attack crew members, who are trying to save the ship with their cards. If too few crew members risk going below deck to effect repairs, the ship’s Emergency Maintenance Assistant (EmMA) adds cards to the pile to help. However, the system has also been compromised and occasionally places damaging cards into the mix, providing plausible deniability to the Menace players. In contrast, Above Deck Actions are conducted in full view of the crew. Most of these abilities have costs, either in Energy or Oxygen, both resources the crew is trying to increase. So, while The Doctor has the ability to heal a crew member and remove a debilitating effect, a Menace player, who may be secretly in control of The Doctor, cares far more that it costs 2 Oxygen to perform the healing.
At some point, someone’s behavior will raise suspicion. But, did they do so because they are trying to fulfill an Individual Goal – or are they a Menace? You can call a vote to expose their true nature. But if they are a loyal Crew member, you’ve just blown precious Oxygen in the effort to detain them. For that matter, was it a Menace player calling the vote in hopes of wasting the air on purpose?
If the Crew can find and eliminate the Menace players – and raise the Energy to a safe threshold before the air runs out, they win. If the Menace can prevent this or kill the crew outright, their mission succeeds. Special commendations are awarded for surviving and for achieving your Individual Goal.
娛樂百分百
凹鳴狼人殺

random card deck 在 粒方不插電 Youtube 的最佳貼文
The Menace Among Us太空狼人殺桌遊版 這裡買: https://www.ruten.com.tw/item/show?22042658513851
講到陣營遊戲 大部分的人想到的應該都是狼人殺、阿瓦隆,但你知道其實有很多比這幾個遊戲更好玩的陣營遊戲嗎? 快來看看吧!
死亡寒冬
CS Files犯罪現場
威脅潛伏 The Menace Among Us (太空狼人殺)
人類懲戒
太空堡壘:卡拉狄加
The Menace Among Us is a semi-cooperative game of intrigue and survival in deep space. Adrift and powerless, your crippled vessel is bleeding oxygen. As you effect repairs, every breath you take brings you one step closer to death. You must work together to restore power before the air runs out — but hidden among you, as loyal friends and crew members, are imposters who have infiltrated security and continue to sabotage the ship. Their only goal is to avoid detection and kill the crew, by force or by asphyxiation. Can you identify them in time and eliminate the threat? Or will succumb to the menace among us?
The Menace Among Us is a 40 to 60-minute, asymmetrical card game for 4-8 players. Each player chooses an Agenda at random, either a loyal Crew member, a deadly Menace or the Coward, who’ll take any side just to survive. Your Agenda card sets a Team Goal and an Individual Goal, as well as outlines any special abilities and the card composition of your individual 13-card deck. Then, knowing your Agenda and Goals, you choose a Character who you believe will best help you achieve them or mask your true identity. Characters add 7 new cards to your deck, shuffle-building a unique combination of cards, as well as provide you two specialized Above Deck Actions.
In this hidden traitor game, how you play your cards and abilities is far more important than the meta game aspects of accusations and denials. Cards are played face down and shuffled together as “Below Deck Actions.” Here, Menace players secretly sabotage the ship’s systems and attack crew members, who are trying to save the ship with their cards. If too few crew members risk going below deck to effect repairs, the ship’s Emergency Maintenance Assistant (EmMA) adds cards to the pile to help. However, the system has also been compromised and occasionally places damaging cards into the mix, providing plausible deniability to the Menace players. In contrast, Above Deck Actions are conducted in full view of the crew. Most of these abilities have costs, either in Energy or Oxygen, both resources the crew is trying to increase. So, while The Doctor has the ability to heal a crew member and remove a debilitating effect, a Menace player, who may be secretly in control of The Doctor, cares far more that it costs 2 Oxygen to perform the healing.
At some point, someone’s behavior will raise suspicion. But, did they do so because they are trying to fulfill an Individual Goal – or are they a Menace? You can call a vote to expose their true nature. But if they are a loyal Crew member, you’ve just blown precious Oxygen in the effort to detain them. For that matter, was it a Menace player calling the vote in hopes of wasting the air on purpose?
If the Crew can find and eliminate the Menace players – and raise the Energy to a safe threshold before the air runs out, they win. If the Menace can prevent this or kill the crew outright, their mission succeeds. Special commendations are awarded for surviving and for achieving your Individual Goal.
娛樂百分百 狼人殺

random card deck 在 肥貓丸 FatCatBall Youtube 的最讚貼文
OTK:05:12、14:17
BGM:https://youtu.be/qIIOza9ZaXw?t=50s
※本牌組勝率很低,請斟酌使用
更多貓貓請看:https://youtu.be/ICskrFLPyMo
飛刀手
Knife Juggler
在你召喚手下後,對一個隨機敵人造成1點傷害
After you summon a minion, deal 1 damage to a random enemy.
亡者之靈
Spirit of the Dead
潛行 1回合在友方手下死亡後,將一張相同的牌洗入你的牌堆,其消耗為1
Stealth for 1 turn. After a friendly minion dies, shuffle a 1-Cost copy of it into your deck.
教派宗師
Cult Master
在友方手下死亡後,抽一張牌
After a friendly minion dies, draw a card.
暗影惡魔
Shadowfiend
每當你抽牌,使抽出的牌消耗降低(1)點
Whenever you draw a card, reduce its Cost by (1).
精靈弓箭手
Elven Archer
戰吼:造成1點傷害
Battlecry: Deal 1 damage.
※本牌組勝率很低,請斟酌使用
附上牌組:
箭無虛發
職業:牧師
規則:開放
1x (1) 亡者之靈
1x (1) 喚醒造物者
2x (1) 真言術:盾
2x (1) 精靈弓箭手
2x (2) 掠寶囤積者
2x (2) 暗影靈視
2x (2) 替死者
1x (2) 末日預言者
1x (2) 血法師薩爾諾斯
2x (2) 見習工程師
1x (2) 降靈術
2x (2) 飛刀手
1x (3) 暗影惡魔
1x (3) 暗言術:死
2x (3) 暮光之喚
1x (4) 教派宗師
1x (5) 集體恐慌
1x (6) 索瑞森大帝
1x (7) 『亡者』伯昂撒姆第
2x (7) 心靈尖嘯
1x (8) 『暗影死神』安杜因
AAEBAa0GDIoB7QWrBtMK1hGGFJbEApDTApeHA6eHA+aIA7CJAwn7AZwChQPlBLEI0cEC6NACqeICof4CAA==
#爐石OTK

random card deck 在 Mamouel/playing-cards: Deck of cards in React ... - GitHub 的推薦與評價
shuffle; deal a random card; show/hide the deck Cards picked are displayed below. Launch project. To see this ... ... <看更多>
random card deck 在 JavaScript Deck Builder: Build Deck, Draw Random Card from ... 的推薦與評價
General points. To empty an array use the length property eg. Rather than use deck.splice(0, 52); use deck.length = 0;; You can simplify the card array and ... ... <看更多>
random card deck 在 How to randomly select a card from a deck of cards and not ... 的推薦與評價
... <看更多>
相關內容