📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有63部Youtube影片,追蹤數超過2萬的網紅lol-エルオーエル-,也在其Youtube影片中提到,Listen and download on your favorite platform♡ https://lol-JP.lnk.to/honoka-futureID Honoka is a member of the Japanese dance and vocal group“lol -エル...
「pick up the call」的推薦目錄:
- 關於pick up the call 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於pick up the call 在 Facebook 的最佳解答
- 關於pick up the call 在 Facebook 的最讚貼文
- 關於pick up the call 在 lol-エルオーエル- Youtube 的精選貼文
- 關於pick up the call 在 Gina music Youtube 的最讚貼文
- 關於pick up the call 在 BarryChen Official Youtube 的最佳貼文
- 關於pick up the call 在 看BBC學英文- 『Could somebody please pick up the phone ... 的評價
pick up the call 在 Facebook 的最佳解答
最近到回”Grill Patio”于当年在这里Bandaran Berjaya成立第一个档口並每晚排长龙的地方,现已扩充到整间店位並在各地区拥有多间分店。除了畅销的汉堡和各种扒类之外,现也有多种椰浆饭,意大利面,鸡翅膀等等。
Recently back to this very first stall of “Grill Patio” at Bandaran Berjaya with long queues always, and now they have expanded to the whole shop lot and more outlets in various areas. Still ordered their best selling burgers and grilled items, and now they have even more choices like nasi lemak, pasta, chicken wings etc.
_______________________________
Grill patio (Halal)
📍 KK branch location : Lorong Berjaya 4, Bandaran Berjaya, Kota Kinabalu, Sabah
https://goo.gl/maps/jbo6ajAfVroy3Yvh7
🕘 Operating Hrs: 10am - 10pm
📞 Any enquiries or to order take-away, advance self-pickup, food delivery, reservations WhatsApp / CALL: http://www.wasap.my/+60168802909
✅ Dine in / Takeaway /Self Pick Up/ GrabFood
🍔 Outlets :
📍 PUTATAN Branch - KIOSK SERVAY HYPERMALL
📍 MENGGATAL Branch- MENGGATAL PLAZA
📍 LUYANG Branch - DAMAI PLAZA
📍 KEPAYAN Branch - CYBER SQUARE
……………………………………………………..
👉🏻Follow us on Instagram :
https://www.instagram.com/eatnhopsabah
#eatnhopsabah #grillpatio #bandarankk
pick up the call 在 Facebook 的最讚貼文
李盈盈与范安婷《13通未接来电》
每一首歌诞生的那一秒,就是向这个世界发出一个新讯息的时刻,如果你没接听到,它就始终是一通未接来电。
13通未接来电,原自李盈盈与范安婷的音乐创作。13个从生活中有感而发的故事, 努力不懈地跨越这个世界去与你连线……而你,愿意接听吗?
Lee EinEin & Anie Fann "13 Missed Calls"
From the moment a song is written, a message is created and sent out into the world. But what if you never got this musical message? What if you never picked up this call?
This is an invitation to pick up 13 calls from Lee EinEin and Anie Fann—13 songs about navigating through life, 13 opportunities to let songs connect us in ways only stories can.
🌐 www.esplanade.com/inmusic
#inmusic #esplanadesg #mydurian
pick up the call 在 lol-エルオーエル- Youtube 的精選貼文
Listen and download on your favorite platform♡
https://lol-JP.lnk.to/honoka-futureID
Honoka is a member of the Japanese dance and vocal group“lol -エルオーエル-”.
This song was produced by KM, one of the most talented producers in Japan today.
The song is about love that hasn’t been erased from memories yet.
This piece is about an important love and the feelings that you can’t forget even though you know that you have to move on because it’s for you and your future.
This work carries a message that only a woman can send to the worldview of Alternative Pop.
◆Official web site
http://avex.jp/lol/
◆YouTube
lol -エルオーエル-Official Channel:https://www.youtube.com/channel/UCTAs...
Playlist:https://www.youtube.com/playlist?list...
◆Twitter
honoka:https://twitter.com/lol_honoka
lol-エルオーエル-:https://twitter.com/lol_avex
◆Instagram
lol-エルオーエル-:https://www.instagram.com/lol_official/
honoka:https://www.instagram.com/honoka_lol/
◆TikTok
https://www.tiktok.com/@lol_avex
Produced by KM
Music & Lyrics : KM & Lil'Leise But Gold
Music Video Credits
Director : Nickey Rourke
Producer : Kento Shinozaki
Production : 蔵屋
Stylist : Keita Uchida
Costume : SUPPLIER
@supplier_official
https://www.supplier-tokyo.com
Lyrics♡
Now remember, Falling Falling is inevitable
Going Going I wanna start walking
Never ever stop, a big 1step
Future is mine
I remember you
Sorry
I didn’t hear that
Lonely, I want to forget just that day, big 1step
Future is mine
1.2.3 call, not answering my phone
4.5.6 move out from your room, change into a dress, redraw the rouge, pressing down my temples
Narrowing my eyes. Do you like pure girls wearing fur? Unfortunately, I don’t have it in me to balance the scales of Love & Money. After I lose and realize, I can’t do anything about it later.
Memories still stacked not erasable
I miss you but I can’t hate you. You are my special. Frustrated feelings
I’m in love, I still hear you
Now remember, falling falling is inevitable
Going Going I wanna start walking
Never ever stop, a big 1step
Future is mine
I remember you
Sorry
I didn’t hear that
Lonely, I want to forget just that day, big 1step
Future is mine
A sunny sky
Wobbly and
Soft determination, cloudy vision, dragging an umbrella that I don’t even use.
The heart flies away. Thoughts of that day, pretend to not know. Falling tears thinking that I might have forgotten something.
One after another, memories become glorified, I hear voice from the heavens saying, stop doing that.
A gulf that cannot be filled even if I pick up all the love and open doors. Sadness is transparent, I feel like I’ve lost my smile. I can’t go back to that place.
I’m sure someday, the memories of my feelings will melt, far and far away.
Soar high, I’m letting the wind carry my body and mind
Memories still stacked not erasable
I miss you but I can’t hate you. You are my special, frustrated feelings
I’m in love, I still hear you
Now remember, falling falling is inevitable
Going Going I wanna start walking
Never ever stop, a big 1step
Future is mine
I remember you
Sorry
I didn’t hear that
Lonely, I want to forget just that day, big 1step
Future is mine

pick up the call 在 Gina music Youtube 的最讚貼文
Don't forget to turn on the bell icon for future uploads 🔔✔️
西洋音樂愛好者✨這裡不會有冗長的介紹文卻是個讓你挖歌的好地方😎
追蹤Gina music社群挖掘更多音樂🌹
facebook👉 https://www.facebook.com/Ginamusicland
instagram👉https://www.instagram.com/ginamusic_yujia/
spotify 歌單👉https://open.spotify.com/playlist/2EfPjFfdqN8NzUwj1XNoZC
🌺贊助GINA讓頻道走得更長久•̀.̫•́✧
Donate and support my channel 👉https://p.opay.tw/WSwM8
想讓更多人認識你的聲音嗎?歡迎投稿😎
Submit your music 👉ginamusictaiwan@gmail.com
For business inquiries about copyright issues, photos and song submissions,
please contact👉 https://www.facebook.com/Ginamusicland
____________________________________________________
Social Media:
▶ Download / Stream link : https://empire.lnk.to/Lonely
👑 Gatsby
https://www.facebook.com/IAmGatsbyOfficial
https://www.instagram.com/iamgatsbyofficial/
https://www.gatsbyofficial.com/
https://twitter.com/iamgatsby
---------------------------------------------------------------------------
Lyrics:
I know that it's wrong
我知道事情的走向不對
Thinking I could call you up
本以為我可以給你打電話挽回
You said we were done
你說我們已經結束了
But I'm not good at moving on
但我卻無法開始新的生活
Cause my memory keeps replaying
回憶揮之不去
And my heart just won't stop breaking
我心碎不已
Oh I wish you'd pick up the phone
我多希望你可以再給我一個機會
And tell me that I’m not the only one who's so afraid to be lonely
告訴我不止我一人如此害怕孤獨
Tell me what we had is tearing you apart and baby, you know it
告訴我 憶起我們曾擁有的一切讓你悲痛欲絕
I still miss you
你明知我仍心悅於你
And I need you
你於我而言不可或缺
And I don't know why we let it go
我不懂為何我們就這樣結束
So tell me that I'm not the only one who's so afraid to be lonely
請讓我知曉不止我一人如此害怕孤單
Can you fall asleep?
你能否安然入睡
Are you wishing you were here with me?
你是否仍希望與我一起
Did you really mean
你對我講的一字一句
Everything you said to me
是否認真
Cause my memory keeps replaying
回憶難以忘懷
And my heart just won’t stop breaking
我心如刀割
Oh I wish you'd pick up the phone
我多希望你可以再給我一個機會
And tell me that I'm not the only one who's so afraid to be lonely
告訴我不止我一人如此害怕孤獨
Tell me what we had is tearing you apart and baby, you know it
告訴我 那些曾經也讓你悲痛欲絕
I still miss you
你明知我仍心悅於你
And I need you
我求你不得
And I don't know why we let it go
我疑惑於為何我們就此告別
So tell me that I'm not the only one who’s so afraid to be lonely
請讓我知曉不止我一人如此害怕孤單
Tell me that I'm not the only one who's so afraid to be lonely
請告訴我你亦需要我
Tell me what we had is tearing you apart and baby, you know it
告訴我 回憶起那些美好也讓你肝腸寸斷
I miss you
你明知我忘不了你
And I need you
你於我而言不可或缺
And I don't know why we let it go
我不知為何我們的感情草草收場
So tell me that I’m not the only one who's so afraid to be lonely
所以讓我知曉你也為此感到遺憾
And tell me that I’m not the only one who's so afraid to be lonely
告訴我不止我一人害怕孤單
(Lonely)
孤單
Tell me what we had is tearing you apart and baby, you know it
告訴我 回憶起往事讓你肝腸寸斷
(I can't take this anymore)
這樣的生活我再也無法承受
I still miss you
你明知我對你情有獨鍾
(I still miss you)
想念你
And I need you
我無法忍受沒有你的生活
(And I need you)
需要你
And I don't know why we let it go
我不懂為何我們就此別過
So tell me that I'm not the only one who's so afraid to be lonely
所以請告訴我你亦無法釋懷
歌詞翻譯: inshepao
#Lonely #Gatsby #Lyrics #西洋歌曲推薦

pick up the call 在 BarryChen Official Youtube 的最佳貼文
數位收聽 🎧 http://barrychen.lnk.to/PTSAY
總會有那麼一首歌,陪伴你度過無數個失眠的夜晚
總會有那麼一首歌,在你失落徬徨時給你鼓勵替你鼓掌
總會有那麼一首歌,在你恐懼的時候給你勇氣
總會有那麼一首歌,在腦海裡久久揮之不去
音樂是生活的調劑、緊緊聯繫著我們的情緒
經過這一切的風風雨雨,按下播放鍵吧!
這一首歌的時間裡,有我給你力量,有我在這陪著你。
Barry Chen新曲『PTS』以輕鬆的節奏,彈跳的旋律
展現出樂觀進取的生活態度,沒有什麼事情是過不去的
體會人生的起起落落高高低低,如果心碎了
真的沒什麼大不了,把它給黏起來、生命依然要繼續。
就是現在,Play This Song and Everything will be alright。
#BarryChen
#PlayThisSong
_
■ Play This Song
詞曲:Barry Chen
每當你難過 Play This Song
每當你寂寞 Play This Song
每當你想起我 Play This Song
請記得抬起頭 Play This Song
去 Night Club 跳個舞 很開心 Yeah
騎摩托 兜個風 煩惱不見
別害怕 有我在 陪你冒險
摔了跤 沒什麼 還有明天
他們都說你變了
過去對你的愛全不見了
Barry 從走到飛之後就墜了
沒有喝酒但也是醉了
Roll me a joint 謝了 我的 Yella
盪過谷底持續想上提升
答應自己今年再賺五個Million
媽媽不再擔心 Now I’m doing better
愛音樂的孩子不會變壞
跟隨自己的步伐跳得多麼自在
拿出自信成為自己理想的天菜
你能夠做到一次 就可以do it twice
每當你難過 Play This Song
每當你寂寞 Play This Song
每當你想起我 Play This Song
請記得抬起頭 Play This Song
去Night Club 跳個舞 很開心 Yeah
騎摩托 兜個風 煩惱不見
別害怕 有我在 陪你冒險
摔了跤 沒什麼 還有明天
心碎了 Pick it up
黏起來 We bounce back
想哭就哭想笑就笑
沒有什麼大不了
不小心跌倒 Stand up
撥掉身上的灰還是站得高
看著鏡子 Girl you look so fine
one two step 沒有 wrong or right
follow your heart 隨他怎麼看
the world is yours 等你來主宰
太多意見不想聽
戴上耳機享受自己
跳過陷阱超級瑪利
節奏是金幣 感受它的威力
Call out 妳的姊妹
帶上我的Whole crew
謝絕所有bad mood
加入一起跳舞
一首好歌能夠化敵為友
卸下武裝地球和平相處
每當你難過 Play This Song
每當你寂寞 Play This Song
每當你想起我 Play This Song
請記得抬起頭 Play This Song
去Night Club 跳個舞 很開心 Yeah
騎摩托 兜個風 煩惱不見
別害怕 有我在 陪你冒險
摔了跤 沒什麼 還有明天
心碎了 Pick it up
黏起來 We bounce back
_
演唱者 Performer:Barry Chen
作詞人 Lyrics:Barry Chen
作曲人 Composer:Barry Chen
製作人 Producer:Barry Chen/JO&H BEAT$ 王淳壹
編曲 Arrangement:JO&H BEAT$ 王淳壹
錄音室 Recording Engineer:JO&H BEAT$ 王淳壹
混音師 Mixing Engineer:JO&H BEAT$ 王淳壹
_
|影像製作|
製作統籌 黃景弘
導演 Director |豆子 Dozkuo
副導演 Assistant Director |陳杰 Jerry
製片 Producer|郭宥 Guo-Yow
執行製片 Line Producer |鄭伊真 Zheng-Yi-Zhen
製片助理 Production Assistant |謝渝茹 Yu Ju Heieh
製片實習生 Producer Intern|馬韡云 Vivian Ma
攝影師 D.O.P |豆子 Dozkuo、陳杰 Jerry
跟焦師 Focus Puller |王俊翔 Chun Hsiang Wang
攝影組 Camara Crew |吳士弘 Shih Hung Wu、廖奕婷 I-ting Liao
燈光師 Gaffer|林冠鐙 KT Lin
燈光助理 Best Boy |陳家閎 Chen Chia Hung、邱柏隆 Qio Bo Long
美術Art Designer |黃慈茵 Huang Tzu Yin
美術助理 Art Assistant |鄒慧琦 Chow Hui Qi
剪接 Editor |豆子Dozkuo
調光 TC|豆子Dozkuo
字卡 Typography |
【特別感謝 Special Thanks】
旋轉牧馬有限公司
詹浩數學資優補習班
猴子電場景

pick up the call 在 看BBC學英文- 『Could somebody please pick up the phone ... 的推薦與評價
『Could somebody please pick up the phone?』 在辦公室接到電話那頭講英文,相信大多數人開開始都會愣一下 如果一開口就支支吾吾那真是太糗了 所以今天我們就來 ... ... <看更多>