📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有710部Youtube影片,追蹤數超過9,410的網紅Miley青山舞莉,也在其Youtube影片中提到,SHOP NOW FROM LINK BELOW! NUGU X MADISON KAI https://abit.ly/miley_madisonkai_youtube ► A B O U T Hello! I'm Miley and I'm from Tokyo. I was raised...
「at random」的推薦目錄:
- 關於at random 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於at random 在 Facebook 的精選貼文
- 關於at random 在 Asther Yinn Facebook 的最讚貼文
- 關於at random 在 Miley青山舞莉 Youtube 的最讚貼文
- 關於at random 在 IKKO'S FILMS イッコーズフィルムズ Youtube 的精選貼文
- 關於at random 在 時事英文 Podcast by ssyingwen Youtube 的最佳解答
- 關於at random 在 At Random | Milwaukee WI - Facebook 的評價
- 關於at random 在 At random Meaning - YouTube 的評價
at random 在 Facebook 的精選貼文
以下有4種語言 中英法韓 如果你認識適合的外國朋友歡迎tag他們!🇹🇼🇬🇧🇫🇷🇰🇷
⬇️English, Français, 한국어 version below⬇️
PS: 這一張是4年前 留長頭髮 剛來台灣 還沒開始拍YT 第一次用Gopro的我 哈哈
🇹🇼
我這幾年住台灣當YouTuber去過了台灣許多地方,看了許多的風景,認識了許多的台灣人。來這邊4年,我從事youtube的工作,而這很容易讓我覺得在台灣該看的我都看完了。
但我每一次滑IG或抖音我都會看到一些影片讓我覺得:“這個是台灣嗎?”
尤其去年,全世界被封城的時候,只有我們住台灣的新住民可以跟朋友炫耀說我們可以出去玩繼續正常生活。這個點也在網路上變成一個被討論的話題,在各國的外國人,看到這些台灣的風景都覺得很驚訝,也開始好奇台灣是怎麼樣的地方。
也因為這次疫情,世界開始看到台灣。這次外交部舉辦【第7屆全民潮台灣短片徵件競賽】 Trending Taiwan潮台灣 ,讓每一個人都有機會成為台灣美好品牌形象片的導演。不管你是外國人或是台灣人,不管你是用手機或是很貴的相機拍,都有機會來幫忙台灣宣傳!
總共有20個獎項,總獎金93萬,趕快來分享你眼中的台灣吧!!
⬇️趕快來報名⬇️
https://bit.ly/2X1hkf4
🇬🇧
Being a Youtuber in Taiwan, I've had the opportunity to travel around and see a fair share of what the island has got to offer. Living 4 years in the same country usually means there's nothing that can really surprise you anymore.
Yet every once in a while, when I lay down scrolling down my socials, I end up looking at insane pictures or videos with a #taiwan in the description. And every time I'm like "No way this picture has been taken here".
Taiwan has been under the spotlight more than it has ever been last year for its good handling of the virus. You could see articles about Taiwan in every country, and scenes of the unaffected daily life of Taiwanese people were going viral on social media. These videos and pictures spreading on Instagram or Facebook were mostly shot by random people wanting to share their life during the pandemic.
No matter if you're a professional film maker or someone who only owns a smartphone, you can send your videos to the Trending Taiwan Short Film Competition Trending Taiwan潮台灣 and maybe see your project become material for international promotional movies.
Try to get a share of the total prize pool of NTD$930,000 and become an ambassador for Taiwan!
⬇️Submit your project right now⬇️
https://bit.ly/2X1hkf4
🇫🇷
En tant que YouTuber à Taïwan, j'ai eu la chance de voyager dans tout le pays et voir plus ou moins tout ce qu'il y avait à voir. Après 4 ans passé au même endroit, c'est facile de se dire qu'on a fait le tour.
Mais de temps en temps, en me baladant sur mon feed Instagram, je tombe sur des vidéos ou des photos de paysages improbables avec un hashtag #taiwan dans la description. Et à chaque fois ça me fait me dire: "Comment ça peut être à Taïwan ça?".
Depuis l'an dernier et la pandémie mondial, Taïwan a bénéficié d'un gros coup de pub à l'international pour sa gestion de la crise sanitaire et l'on a pu lire ou entendre des reportages sur le pays dans les quatre coins du monde. Des images de la vie quotidienne restée presque normale à Taïwan faisaient le buzz sur les réseaux sociaux et ont permis à beaucoup de poser pour la première fois les yeux sur cette magnifique île qu'est Taïwan.
Ces images qui ont fait le tour du monde étaient filmées par des gens lambdas voulant partagés leur vie ici et c'est exactement ceux à qui s'adresse le concours du "Trending Taiwan Short Film Competition" Trending Taiwan潮台灣. Que vous soyez un cinéaste aguerri ou juste muni d'un smartphone avec appareil photo, vous pouvez partager vos court métrages et devenir l'un des ambassadeurs de Taïwan à l'international!
Les gagnants du concours pourront recevoir un total de NTD $930,000 et voir leur vidéos apparaitre dans les campagnes promotionnelle du pays!
Venez participer et partager vos vidéos:
https://bit.ly/2X1hkf4
🇰🇷
대만에서 3년동안 유튜브 영상을 찍으면서 갈곳을 이미 다 가봤고 볼 것을 이미 다 본것 같은 느낌 들기 시작했어요. 4년이나 같은곳에 살면 길 가다가 놀라울만한 일이 거의 없어요.
그래도 가끔씩 인스타 볼때 천국 같은 풍경 사진 나오는데 사진 밑에 해쉬태그 #taiwan 이라고 써 있더라고요
이럴때마다 이런 사진 제가 잘 아는 대만에서 찍을 수 있다는거 믿기지 않아요.
작년부터 전세게가 락다운중이었을때 SNS에서 대만과 관련 뉴스 퍼지기 시작했어요. 대부분의 사람들이 나가지 못했을때 대만에서 거의 평소대로 지내고 있었어요. 그 화면들 인스타나 패북에서 보일 수 있었고 대만에게 어마어마한 광고가 되었고 그영상이나 사진들이 대부분 일반인이 찍은것이었어요.
올해도 전세게한테 대만을 보여주기 위해서 대만 외교부 행하는 潮台灣 Trending Taiwan潮台灣단편 영화제 열리고 대만에 관한 이야기 찍고 싶어하는 누구나 참가할 수 있어요!
핸드폰을 써서 찍은 영상으로도 참가할 수 있으니 부끄러움없이 작품을 보내주세요~~
상 20개, 총 93만 대만 달러의 장려금이 있으니 한번 참가해보세요~
https://bit.ly/2X1hkf4
#第7屆全民潮台灣
at random 在 Asther Yinn Facebook 的最讚貼文
Mac and Cheese with Baked Beans 💛
Ayam Brand Baked Beans has always been my favorite when it comes to home cook food. It saves my time and effort in the kitchen!
Most importantly, they are packed with fiber and plant-based protein with NO preservatives, NO added MSG, NO GMOs and NO trans fat! Safe and Halal ✨
#AyamBrand products are available at major supermarkets and hypermarkets, get them now!
Stand a chance to win away Ayam Brand products worth RM50 🎁
Just comment below “I want to have Ayam Brand Baked Beans with….” and tag 2 friends.
Two random winners will be contacted by Ayam Brand Malaysia
*Contest ends on 30 Sept 2021
*Malaysian Citizen only
*T&C Apply
Check them out at:
https://www.ayambrand.com.my/
#ayambrand #ayambrandmy
#giveaway #giveawaymalaysia #giveawaymy
at random 在 Miley青山舞莉 Youtube 的最讚貼文
SHOP NOW FROM LINK BELOW!
NUGU X MADISON KAI
https://abit.ly/miley_madisonkai_youtube
► A B O U T
Hello! I'm Miley and I'm from Tokyo. I was raised in Singapore, Indonesia, and Japan so I think some international kids could relate to me. My videos are focused on my everyday life as a Waseda student but I also love sharing my everyday fashion, vlogs, and other random things. I hope you enjoy💗
► S O C I A L S
Instagram http://instagram.com/milez728
Tik Tok https://vt.tiktok.com/hs2D23/
Twitter https://twitter.com/miley_728
► C O N T A C T
Business Inquiries info@qualiam.com
http://www.qualiam.com/contact.html
Japan 生まれ Indonesia, Singapore, and Japan 育ちの青山舞莉です!早稲田大学の政治経済学部に通っています。スポーツ、フード、おしゃれ、メイク、お出かけ、なんでも経験したい好奇心旺盛なミーの大好きなことをアップしていきます!
ー年齢は?Age?
21歳 im twenty one :)
ー誕生日はいつ?Birthday?
2000年7月28日 July 28th 2000
millennium baby (did i spell that right?)
ー学年は?what year are you?
今は早稲田の大学4年生です!2021の秋から4年生になりました!im a senior in college!! waseda university yay
ーどこの人?where are you from?
im full japanese!! 日本人!
ー身長は?Height?
156cm! i think thats like 5'1
ーカメラは何使ってる? what camera do you use?
Canon
ー編集ソフトウエアどれ使ってる?Editing software?
Adobe Spark for thumbnails & Final Cut Pro for my videos :)
青山舞莉のInstagram
https://www.instagram.com/milez728/
青山舞莉のTwitter
https://twitter.com/miley_728
青山舞莉のTikTok
https://t.tiktok.com/i18n/share/user/...
Contact
http://www.qualiam.com/contact.html
CREDIT
··················································
Intro by SIMPLY INTROS!
https://youtu.be/u4q69J2PwXM
··················································
at random 在 IKKO'S FILMS イッコーズフィルムズ Youtube 的精選貼文
都立大学駅より徒歩15分。
2019年12月、「CHINESERESTRAUNTわさ」の跡地にオープン。
中華式の厨房でイタリア料理を作るのは「TACUBO(タクボ)」で腕を磨いた笠井シェフ。
さて、一体どんな料理が出てくるのだろうか?
笠井
https://tabelog.com/tokyo/A1317/A131702/13242439/
【イタリアン①】「ラ・ピッコラ・ターヴォラ、マッシモッタビオ、キャンティ、ナポリス」
https://www.youtube.com/watch?v=nFpv-qoAr84&t=20s
【イタリアン②】ダイ―サ at.中目黒
https://www.youtube.com/watch?v=vGK9exNEc5Y&t=2s
【イタリアン③】ベントエマーレ at.不動前
https://www.youtube.com/watch?v=A4AKwJjesnM&t=3s
【イタリアン④】ラ トリプレッタ at.武蔵小山
https://www.youtube.com/watch?v=OaiUVTxN15s
【イタリアン⑤】Hostaria Casa Bella (ホスタリア カーサベッラ) at.外苑前
https://www.youtube.com/watch?v=8l2XSYmOWKE
【イタリアン⑥】COGS DINING KAGURAZAKA at.神楽坂
https://www.youtube.com/watch?v=tyCpnw8b_n8
【イタリアン⑦】Restaurant Naz at.軽井沢
https://www.youtube.com/watch?v=SkOXw6BwQRg
【イタリアン⑧】笠井 at.都立大学
https://www.youtube.com/watch?v=7KKPGCyKm7c
【イタリアン⑨】Da GOTO at.三越前
https://www.youtube.com/watch?v=dW6AI_Al1Mo
【MUSIC】
Crossing the Rubicon - Jakob Ahlbom
Distant Fortune - Daniel Kaede
Random Acts of Kindness - Airae
Amaze - Major Tweaks
If Love Feels like a Fever - Particle House
Sailing - Gary the Canary
★instagram
https://www.instagram.com/ikkos_films/
★サブチャンネル「IKKO'S FILMS EXTRA」
https://www.youtube.com/channel/UC_b7JhrPKWAv0lU3509_xOA
★「品川イッコー 公式ブログ」
http://www.ikkoshinagawa.com/
★Twitter
https://twitter.com/ikko2005
at random 在 時事英文 Podcast by ssyingwen Youtube 的最佳解答
因病毒延後的東京夏季奧運終於在週五晚上開幕。煙火照亮了幾乎空無一人的體育場,色彩繽紛的場面異常低調,場外上百名抗議者高呼 “Stop the Olympics”。挫折與風波不斷的 2020 東京奧運正式開始。
📝 訂閱講義 & 朗讀稿 (只要 $88 /月):https://bit.ly/ssyingwen_notes
🤩 延伸閱讀:https://ssyingwen.com/ssep39
🖼️ IG 單字卡: https://bit.ly/ssyingwenIG
♥️ 請我喝飲料:https://bit.ly/zeczec_ssyingwen
📪 合作邀約:ssyingwen@gmail.com
———
朗讀內容來自Associated Press (AP)
👉 選讀片段文字: https://www.facebook.com/groups/ssyingwen/posts/270656328153947/
👉 完整文章連結在:https://apnews.com/article/2020-tokyo-olympics-opening-ceremony-8b75b92f36477af48612c70a2b7104e1
———
本集 timestamps
0:00 Intro
0:08 第一遍英文朗讀 (慢)
3:13 新聞單字片語解說
21:42 第二遍英文朗讀 (快)
———
更多奧運相關單字:https://ssyingwen.com/ssep20/
本集提到的單字片語:
IOC (International Olympic Committee) 國際奧委會
Opening ceremony 開幕典禮
Random 隨機
Parade of Nations 各國入場的遊行
Greece 希臘
Athens 雅典
Afghanistan 阿富汗
Iceland 冰島
Alphabetical order 字母排列
Kyrgyzstan 吉爾吉斯
Tajikistan 塔吉克
Pakistan 巴基斯坦
Flagbearers 掌旗手 / 掌旗官
Naomi Osaka 大阪直美
Tonga 東加王國
Shirtless 打赤膊
Oiled up 身體抹油
Shirtless Tongan 打赤膊的東加人
The elephant in the room
Vaccine 疫苗
At least 1 dose 至少打了一劑
Fully vaccinated 完成接種
“Stop the Olympics” 停止奧運
Controversies 爭議
The Holocaust 納粹大屠殺
Fukushima 福島
Miyagi 宮城
Shizuoka 靜岡
Training 訓練
Quarantine 隔離
Olympic Village 選手村
Olympic creed 奧運信念
Once in a century 一百年一次
Once in a lifetime 一生一次
Once in a blue moon 很少發生
Once in a generation 一代一次
Once in a thousand years 一千年一次
Cornucopia 大量且多樣的
————
#podcast #東京奧運 #開幕典禮 #學英文 #英文筆記 #英文學習 #英文 #每日英文 #托福 #雅思 #雅思英語 #雅思托福 #多益 #多益單字 #播客 #英文單字卡 #片語 #動詞 #國際新聞 #英文新聞 #英文聽力
at random 在 At random Meaning - YouTube 的推薦與評價
Video shows what at random means. in a random manner. haphazardly. At random Meaning. How to pronounce, definition audio dictionary. ... <看更多>
at random 在 At Random | Milwaukee WI - Facebook 的推薦與評價
At Random , 密爾瓦基。 8608 個讚 · 150 人正在談論這個 · 10128 個打卡次。 Bay View's historic specialty cocktail lounge, open since 1964. ... <看更多>