📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有473部Youtube影片,追蹤數超過35萬的網紅阿兜仔不教美語,也在其Youtube影片中提到,【阿兜仔不教美語】 🔔 阿兜仔 訂閱🔥 ► https://pse.is/39792r 📸 阿兜仔IG ► https://pse.is/MBW4V 🔵 阿兜仔 FB ► https://pse.is/BAPYU 【Damn! I love Taiwan】 🖥 ► http://damn...
damn you 在 Facebook 的最佳解答
【Hello Hater】@鬼才做音樂 2021 Ghosician
《Hello Hater》Youtube 高清版MV: https://youtu.be/xyos93gW5e4
The Making Of《Hello Hater》幕後花絮 Youtube高清版: https://youtu.be/RCV8qTt4ktY
《Hello Hater》數位音樂下載 Online Music Download:https://lnk.to/HelloHater
Lyric Version《Hello Hater》動態歌詞版 Youtube高清版 : https://bit.ly/3hSHUio
-
Uhh Hello Hater
啊 哈嘍 黑特
Uhh Mother Fxcker
啊 馬德法克
我又來了 (我又來了)
I am here again (I am here again)
我又來了 (我又來了)
I am here again (I am here again)
我又來了來了來了來!
I am here again, again!
我就是教壞囜仔大細 (幹)
I am the bad influencer to the multitudes (Fxck)
袂爽來找恁爸 (來)
If you are upset, come to me (Come)
假的帳號 到處留言
Using fake accounts to leave comments around
面對面陰莖縮進裡面 (咻)
Dick recoils while face to face (Aahs)
我教壞囜仔大細 (吶)
I will influence the multitudes negatively (Nah)
袂爽來找恁爸 (來)
If you are upset, come to me (Come)
確診陽痿 存一支嘴
Impotency leaves you with only a mouth to talk
幹恁阿公ㄟ踹共!
Fxck You, come and face me directly
踹! 呸!
Show up your face!
你頭腦裝洨
Your brain is filled up with semen
眼睛髒看東西都黑掉
Everything looks black in foul eyes
天生雞雞太小 薪水太少
Born with tiny dick, drawing a little salary
只能用鍵盤來高潮
Orgasm only via keyboard
因為想法跟你的不同
As my view is different from yours
所以才能夠比你成功
Therefore I attain greater success than you
看到社會不公 袂爽就講
I would voice up against injustice
你只能跪拜舔騙讚歌頌
You can only truckle and flatter
才不鳥限流被黃標 (想唱啥就唱啥我驕傲)
Never be bothered with restricted flow or yellow tag (I am proud to sing whatever I like)
還開了抖音微博帳號 (有空就麻煩快點舉報)
Registered TikTok and Weibo accounts in addition (Please report when you are available)
整天斷章取義 亂貼標籤
Always misinterpret and label me as you like
根本噁心犯賤 他媽嘴臉
Absolutely disgusting and cheap ugly face
快來黑我 訂閱 分享
Twisted my initial meaning, then subscribe & share my video
害我 每天在賺大錢
Making me tons of money
看見我執迷不悟 刀槍不入
How stubborn and invulnerable I am
脫了你三件內褲
Take off your three briefs
我就是全身的酷 看別人吐
I am damn cool, yet you threw up
Such an outlandish way of gesture
幹恁娘這種程度
Bought bullets cost thirty thousand Pew Pew Pew
買了個銃子 三萬塊嘟嘟嘟嘟
Talkative non-stop, I'll shoot your house
靠北我射你住處
I just need trap but not protection
我只要陷阱 不需要別人的護
Fxck your busybody noisy pig
操你妹雞婆的豬
I am not afraid, I choose to do only serious task
我沒在怕的 我只幹大的
Go to hell bastard, I wanna rebuke till you can't refute
去你的Sucker 壓著你罵的
Consistent tactics similar reply in comments, damn
一貫的伎倆 留言我操
Shut up when you have finished, I deal with big cases
罵完了閉嘴 老子搞大的
I am a sinner never give a shit about moral
我是個罪人 沒在管道德
場子可燥了 沒啥可套的
The place is so boring, nothing is interesting
我只要錢 我不要命
I am willing to risk for money
快給我Shit 而且要Free
Give me shit and it must be free of charge
女兒長大 學床叫
Daughter grown up mature begin to moan
臭婊子幹完 還要
After done first round, initiate another round
小孩照三餐 打掉
Repeated abortion non stop
懶得聽廢話 I’m Bounce
Fed up with the rubbish, goodbye
哈哈 (哈)
Haha (Ha)
幹妳的Bitch啪啪 (蛤?)
Fxck you bitch (Alright?)
媽媽生的臭俗辣 (臭俗辣)
Born to be a coward (Coward)
爸爸生的破麻 (Fxcked up)
Born to be a whore (Fxcked up)
留言區的廢物那些笨豬沒有惡意
All these comments left by the pigs are senseless
但是就是為了能在網路上面To The Top
Just to catch attention online
需要的是共鳴 才能發現
Demand for support, debunk the myth
佩服你的勇氣沒有準備還想Fxck
Salute your courage of simply fooling around
按你讚 快給我笑 (給我笑)
Give you Like, smile to me please (Smile to me)
討論度還在堆高 (長高)
Discussion is getting more intense (Growing)
把你爸媽Shut Down
Shut down your mom and dad
緬甸街中和Town (栗子)
Myanmar Street in Chunghe Town (Chestnut)
聽我的歌 每天看我的影片
Listen to my songs and watch my videos every day
像吞我的洨 然後吃我的大便
Like drink my semen and eat my poo
媒體就愛 報導轉貼
Media loves broadcast and re-post
你恨死恁爸 一直打臉
You hate me to death but slap in your own face
Hey Hater Loser Keyboard Warrior
嘿 黑特 魯蛇 键盘侠
You Mother Fxcker Come and Lick My Shit
馬德法克快來舔我的大便!
-
欲網購黃明志最新實體專輯《亞洲通才》及歷年專輯和周邊商品請到。Purchase Namewee Latest 《Asian Polymath》 , Others Music Albums & Merchandises Please log in to https://namewee4896.com/
Namewee 黃明志 Telegram Channel :
https://t.me/nameweeofficial
Namewee 黃明志 Official Facebook Fan Page:
https://www.facebook.com/namewee/
Namewee YouTube Channel Link:
http://www.youtube.com/namewee/
Namewee Twitter Channel:
@NameweeO
#Namewee #黃明志 #HelloHater
damn you 在 Facebook 的最佳貼文
[記得四哥發哥都已見過面。後來榮升主角太突然](*)Dear, write some god damn thing
TLDR:下個月開始,《信報財經月刊》有我。記得買。
1. 我有無數咁多古怪嘅寫作習慣。其中一個唔少人知,就係我篇文寫乜都未知,幾時會有都未知,但一早會有個題。例如我篇《楊枝甘露的誕生》,聽講係愛情小說,寫咗廿幾年只係得個題。《第一次的親密接觸》嘅作者痞子蔡都有呢個習慣,小說一定有咗個題先,然後先寫。
2. 我更進一步,十幾廿年前已經會有個題,等件事發生。好似門捷列夫個元素週期表咁(Periodic table,啲化學畀返晒老師未?)。同你估嘅唔同,當年佢整個表嗰時,唔係列晒1—100出嚟,當時唔少元素根本未被發現。但佢一早留定位,知道會有一個咁特性嘅元素,一直都在,只等你發現。後來果然後人就發現到嗰啲元素,性質同佢預期嘅差不多一樣,成件事實在型到不得了(**)
3. 當然我唔係門捷列夫,我不能確定呢一日會發生。可能十年,三十年,甚至死嗰日都唔會有。因為涉及太多嘢。但總之,呢篇文個題,係我好多年前已經諗的,just in case.而家就可以解封了。
4. 忘掉那一天,記不起是那年,但應該係好早期,我甚至未做金融。有一年,我在書展,見到有個唔靚仔嘅瘦皮猴,推銷緊佢本新書,好似唔太多人理佢。佢話可以幫我簽名
5. 嗰個,就係龔耀輝。
6. 後來嘅事,係我開始打銀行工,開始睇《信報》。一來公司有,二來Reuters部機上面有。
7. You are what you read,最早期我可能受陶傑張小嫻影響,後來我就受游清源影響。金融方面,當然就係睇《信報》時,蔡東豪同龔耀輝。
8. 等我懷念下當年,circa 2004 -2006,我在美國銀行大廈返工(蕉行嘛)(***),閒唔時就係睇下《信報》,就係睇佢幾位老哥。當時我成日午餐就在和記大廈(已拆)間星巴克,記得嗰時個姐姐認得我,我漏低咗嘢幫我keep住,仲手寫住我個名(星巴克姐姐知你個名有幾奇?我又唔會用假名)。硬係覺得嗰時嘅人心好啲,星巴克啲女都靚啲。定只係嗰時後生,入世未深?
9. 無論如何,嗰時我就心諗。嘩,幾時有一日到我會寫《信報》?
10. 至少在2000年時,我已經發夢在報紙在專欄作家。當時厚著面皮厚著包皮咁電郵某人請教,仲畀佢第日在專欄串我。但,佢講得冇錯嘅係,write some god damn thing(唔係原文).呢個亦係我而家叫啲小朋友做嘅嘢。
11. 時間飛到去大約十年前,《信報》搞咗個「動筆動思考」嘅東西。作家培瞓,或者當搵新血咁。當時我在耆英已撈得不錯,但寫作嘅事業,等於零。
12. 而去到呢個位,我實在so gay都要講。我大學年代識嘅嗰位網友,已經實現咗自己嘅夢想(算係?),在有線講咗波好多年。佢點入行架呢?正係參加咗有線嘅比賽。我仲要係睇住嗰場比賽,甚至記得佢係講曼聯對車路士。舊年同佢食飯講起,佢當然完全唔記得呢件事。
13. 不能話受佢影響,因為當時佢已經講咗好多年。但總之,「動筆動思考」壇嘢,我就覺得自己都係要write some god damn thing,寫咗篇文去。三十歲那日不要臉,參加了挑戰
14. 有圖有真相,我都唔知我仲keep住呢個email
15. 結果?我有個朋友入圍(唔係寫金融的),本人當然名落孫山。明顯寫得未夠好,或者緣份未到。
16. 又或者,係未夠努力。
17. 當年某評審睇咗我篇文,問我有冇啲正經啲嘅(陰功,我以為嗰篇已經好正經!)。正常真係好飢饑嘅人,應該會寫多篇。但我好似只係回佢:冇喎,這是我的風格。(唔肯定有冇第二句)
18. 咁,who cares你咩風格?邊位?
19. 況且,Let’s be frank,機會成本。我由中學開始已經鍾意寫嘢,但畢竟你鍾意唱歌同你去紅館開演唱會係兩回事,你鍾意踢波同你去咗奧脫福踢一隊又係兩回事。
20. 正如上面講,當時我在耆英都撈得不錯。當然都熱愛寫作,但我都熱愛空姐(誰不愛),但我總不會日日走去約空姐,對不?唔使返工咩。咁我摶上位升職加人工緊要,定寫文緊要?
21. 你可以話即係我未夠熱愛,或者寫得未夠好,總之whatever,就又過咗十幾年。媽的,人生有幾多個十幾年?
22. 但生命嘅嘢真係唔係一條直線,卒之2021年,《信報財經月刊》,搵我寫嘢!
23. 我唔記得係「四哥」定「發哥」講(懶FC了),當年《信報》搵佢寫文,佢嘅反應係「𦧲飯應」(原文照錄)。亦係我早兩星期嘅心情。
24. 講多無謂,write some god damn thing.稿已交,講日本股票。10月頭會出版,到時記得買。最開心係佢地可以畀我寫三千字。
25. 當然啦,如今我四十看從前,枝筆已鬆軟。「四哥」「發哥」都冇再在《信報》寫文。但唔緊要,依然仲有好多好嘅作者。唔係講我啦。你也可以是孔少林,我們都是原復生。
26. 彩蛋:當年,2006,唔知「四哥」定「發哥」在《信報》,貼中意大利拎冠軍,鳩威咗一排。今年,2021年,本人一樣貼中意大利拎冠軍!固然都係七分好彩,但,至少寫波,我就應該勝過「四哥」「發哥」了。
27. 彩蛋二:居然畀我搵得返當年掟去嗰兩篇稿,不如遲下貼上嚟?而家睇返,「都唔係真係咁差啫」,「咪同我而家啲文差不多」。證明我過去十幾年都冇乜進步過,但可能啲讀者品味越嚟越低,造就我都有人睇。又或者「四哥」「發哥」等等收晒山,池中無魚蝦自大,廖化作先鋒咁。
(*)都係鍾意高登改版多啲。「記得飯島 松島 都已見過面 後來榮升主角太突然」。原諒我騎劫咗一個應該相當文藝中產嘅post,但,唔通中產文青唔睇AV?早兩年我去到松島(牛舌!)打卡亦都係貼呢句歌詞。不過in case anyone care,我係既唔睇飯島,亦唔睇松島嘅。甚至三上悠亞 波多野結衣我都係唔睇的。懶係唔跟主流嘛,由呢啲嘢都睇得出。但又不過,你見我買股票又係買返 Facebook Microsoft 等等,主流到唔主流,所以唔好輕易將 「平時嘅口味」同投資嘅性格撈埋嚟講。正如跑馬拉松嘅人,未必買股票有恒心。運動員在場上可以受壓,可以超高心理質素,但唔等於唔會有心理問題,唔會亂買嘢傾家蕩產。世界唔係咁簡單
(**)好多書有講,例如呢本(https://bityl.co/8eCm)
(***)無獨有偶,嗰時我去耆英證券見工,都係嗰度!仲要係樓上!「所以唔使請假見工」。最正係我take咗佢地offer嗰日,放工就撞到後來嘅鬼頭上司同我一齊迫電梯。
==============
已烴2000人訂!多謝大家!Two thousand people can't be wrong!(扯,幾百萬人冇訂添!).下一個目標當然係攞你命3000!
==============
月頭訂最抵!一週年!比別人知得多。subscribe now(https://bityl.co/4Y0h)。Ivan Patreon,港美市場評點,專題號外,每日一圖,好文推介。每星期6篇,月費100. 畀年費仲有85折,20/40年費VIP 送本人著作一本。
damn you 在 阿兜仔不教美語 Youtube 的精選貼文
【阿兜仔不教美語】
🔔 阿兜仔 訂閱🔥 ► https://pse.is/39792r
📸 阿兜仔IG ► https://pse.is/MBW4V
🔵 阿兜仔 FB ► https://pse.is/BAPYU
【Damn! I love Taiwan】
🖥 ► http://damnilovetaiwan.com
🛒 蝦皮► https://sho.pe/3jalf3
🛒 Pinkoi► https://pse.is/3jj4e4
🛒 PCstore► https://pse.is/3hyegt
📸 IG ► https://pse.is/utr56
🔵 FB ► https://pse.is/3l53f9
【談商業合作】
📧 ▶ damnilovetaiwan@gmail.com
#黑素斯 #阿兜仔 #阿兜仔不教美語 #COW杯 #COW杯的星期一 #靠我愛台灣 #damnilovetaiwan #台灣 #台北 #Taiwan #老外 #外國人 #外国人

damn you 在 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
kkbox👉https://www.kkbox.com/tw/tc/profile/GqICYlKUZnCZyC0RO7
🌺贊助GINA讓頻道走得更長久•̀.̫•́✧
Donate and support my channel 👉https://p.opay.tw/WSwM8
🌸本影片與 High Beats 合作宣傳🌸
想讓更多人認識你的聲音嗎?歡迎投稿😎
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://open.spotify.com/track/68TA7P1y9S9zs1MVMNTAih?si=d8b226edb97e488a
👑Twin Lights:
Facebook: https://www.facebook.com/WeAreTwinLights/
Instagram: https://www.instagram.com/twinlightsmusic
Spotify: https://open.spotify.com/artist/4gEWFd04T7qHVgdV96pyZo
👑Tom Konway:
Instagram: https://www.instagram.com/tomkonway/
Spotify: https://open.spotify.com/artist/6ZoXmGFZTDpit3AXs299bl
Lizzy Petitt:
Instagram: https://www.instagram.com/lizzy_joep
Spotify: https://open.spotify.com/artist/7e1VIYUbzvNU85wPWjYVYK
👑High Beats:
Instagram: https://www.instagram.com/highbeatsmusic/
Facebook: https://www.facebook.com/highbeatsmusic
Spotify: https://open.spotify.com/artist/7LhJFe6rXO8TmqfAzQP1SS
---------------------------------------------------------------------------
Lyrics:
I lie in bed after dark
And I talk to the stars
They tell me that it´s okay
So far away you might as well
Just be on mars
Some reason I'm not okay
So I convince myself
That I am bigger than this mess
What´s the point in being suffocated
With distress
I need my space
I´ll live with grace
Cuz I can´t breathe between the days
Of traveling through my feelings
I need my space
I need my space
I´ll live with grace
I lie in bed after dark
Waiting for you
Cuz you said that you would call
Forgot I changed my name to pluto
Boy you got me feeling so damn small
So I convince myself
That I am bigger than this mess
What´s the point in being suffocated
With distress
We can´t breathe
Any longer
We need some air
I need my space
I need with grace
I said I´ll leave with grace
Cuz I can´t breathe between the days
Of traveling through my feelings
I need my space
I need my space
I need with grace
I said I´ll leave with grace
Cuz I can´t breathe between the days
Of traveling through my feelings
I need my space
#Space #TwinLights #HighBeats #Lyrics

damn you 在 Rachel & Jun's Adventures! Youtube 的最佳貼文
Save 33% on your first Native Deodorant Pack - normally $36, you’ll get it for $24! Click here https://bit.ly/nativeracheljun3 and use my code RACHELJUN3
Rachel Maksy's dark academia video: https://youtu.be/2mSx-np1uG4
THRIFT SHOOOOOP! Over the past couple years I've been seriously cutting down my wardrobe so I haven't been back to the thrift stores very often. Oh how I have missed my Japanese thrift stores! But I recently found out about the Dark Academia ~aesthetic~ and I NEEDED to see if I could find some looks! Plus, it's so damn hot here in Japan and turns out most of my wardrobe is plastic (polyester, etc) which is like the worst thing you can wear since it's not breathable?? You learn something new every day. We managed to find quite a few things in my style made of breathable, cotton and linen fibers!
★Our new merch!!! https://crowdmade.com/collections/junskitchen
The official Crowdmade website is the ONLY place we're selling merch!
★ Patreon! http://patreon.com/junskitchen
►FOLLOW US ε=┌( ・д・)┘
Our Japan channel ⇀ https://www.youtube.com/RachelandJun
Jun's Kitchen ⇀ https://www.youtube.com/JunsKitchen
Twitch ⇀ https://www.twitch.tv/rachelandjun
Twitter | Instagram *@RachelandJun*
►EQUIPMENT (Amazon affiliates links) _〆(・∀ ・ )
Camera ⇀ GH5 (http://amzn.to/2GJWsN2)
►MUSIC ♪♪(o*゜∇゜)o~♪♪
Music from Epidemic Sound: http://share.epidemicsound.com/rDvsz
