📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有38部Youtube影片,追蹤數超過39萬的網紅CON THỎ,也在其Youtube影片中提到,Hôm nay thỏ sẽ để cho chú alex tự chọn mua quần áo trên mạng và chúng mình cùng thử chấm điểm các outfit của chú alex xem thế nào nhé mọi người ơi ! N...
「not uniform」的推薦目錄:
- 關於not uniform 在 Taipei Ethereum Meetup Facebook 的最佳解答
- 關於not uniform 在 Honeyz Facebook 的精選貼文
- 關於not uniform 在 Angie0_0 Facebook 的最讚貼文
- 關於not uniform 在 CON THỎ Youtube 的最佳解答
- 關於not uniform 在 Cass Chiu Youtube 的最佳解答
- 關於not uniform 在 The Thirsty Sisters Youtube 的最佳解答
- 關於not uniform 在 New Opportunities in Non Uniform Sampling - YouTube 的評價
- 關於not uniform 在 LibGdx Shader ("no uniform with name 'u_texture' in shader") 的評價
not uniform 在 Honeyz Facebook 的精選貼文
While it should come as no surprise that I’m an ardent Disney fan, what might surprise many of you is which Disney Princess I have in my earliest childhood memories!
It’s not Cinderella, Snow White or even Belle!
It’s actually Ariel from The Little Mermaid! 🧜♀️
It was the first Disney movie my beloved mommy brought me to see at the cinema and she even got me all the original (and I should add not so child-friendly) books by Hans Christian Andersen.
While I really related to Ariel's curiosity about the big wide world, it was her strength that struck me the most! She was willing to give up her voice for what she believed in, confident that her actions would speak louder than her words and she would still be able to connect with her love.
I feel these messages are more important now than they have ever been, it’s easy to be afraid and withdraw from the rest of the world, but I for one love to explore and see the beauty of the world, all the different cultures and traditions! And even if we don’t all speak the same language, kindness is universal!
It all makes this charming Ariel charm from Pandora's DISNEY PRINCESSES COLLECTION all the more special to me and I find her tagging along on my modern-day adventures, on my uniform, pencil case and even handbag! Keep swiping for photos!
In the famous words of Sebastian the crab, what a soft shell I’m turning out to be! 🦀
#DisneyxPandora #PandoraSG
not uniform 在 Angie0_0 Facebook 的最讚貼文
Blue skyyyyyyy <3
Is not easy to get blue sky in here, I think I'm the lucky one during the photoshoot 😳😳😳
=================
Will send out the full uniform set (30hd photo) tomorrow! Don't forget to unlock tier15 uniform set and above for more photos~ link at bio or below comment ^^
JK model by Angie0_0
photo by Fritz S. Akma
not uniform 在 CON THỎ Youtube 的最佳解答
Hôm nay thỏ sẽ để cho chú alex tự chọn mua quần áo trên mạng và chúng mình cùng thử chấm điểm các outfit của chú alex xem thế nào nhé mọi người ơi !
Newchic is an online global website that offers many types of fashion items. Use my coupon ASIA20 to get 20%off discounts.
Check their website:https://Newchic.vip/YGXp
Men Fashion: https://Newchic.vip/YGXt
Items mentioned in this video:
Plaid Print Cotton Shirt: https://Newchic.vip/YGWV
Solid Color Front Open Cardigans : https://Newchic.vip/YGWX
Solid Cotton Ripped Cuff T-Shirts: https://Newchic.vip/YGWZ
Heavy Industry Motorcycle PU Leather Jackets: https://Newchic.vip/YGX1
Solid Cargo Pants With Ribbon : https://Newchic.vip/YGX3
Classical Plus Velvet Thick Baseball Uniform Jacket: https://Newchic.vip/YGX5
Get to know more about Newchic:
Fb: https://www.facebook.com/pg/NewchicSEA/
Ins: https://www.instagram.com/newchic_asia/
Youtube: https://www.youtube.com/channel/UC46aspKMc1QJ8tCWBLhJVpQ
------------------------------------------------------------------------
BE SOCIAL WITH ME!
------------------------------------------------------------------------
Subscribe! ► https://goo.gl/9662b3
Follow me on Instagram! ► https://www.instagram.com/contho/
Like me on Facebook! ► https://www.facebook.com/con.tho.35
► Liên Hệ: contho1104@gmail.com
/vlog camera : sony a5000
/beauty camera : canon 7D
/phần mềm edit : premiere / final cut pro
------------------------------------------------------------------------
VUI LÒNG KHÔNG ĐĂNG TẢI LẠI (RE-UP) LÊN KÊNH CỦA BẠN. CHÚNG TÔI LÀ YOUTUBE PARTNER NÊN KHI PHÁT HIỆN RE-UP SẼ BỊ REPORT KHIẾN KÊNH BẠN CÓ THỂ BỊ XOÁ HOẶC HẠN CHẾ CHỨC NĂNG.
---------------------
© Bản quyền thuộc về CON THỎ
© Copyright by CON THỎ Channel ☞ Do not Reup

not uniform 在 Cass Chiu Youtube 的最佳解答
Hii this was actually so exciting to film and edit and rewatch! I hope you enjoyed it as much as I did! Life is too short to not cherish anything and everything, I lowkey used to hate wearing my school uniform! but now I miss it :( I know I will cherish these people and these photos forever tho, thank god I filmed this day now we can keep looking back to it.
我以前好唔鍾意著校服,依家突然掛住添🥺好彩哥日真係有拍!做人真係要唔好後悔!下年拍完可以再睇返呢條!希望你地鍾意啦❤️
Instagram: @cassandra.chiu
Business Inquiries 工作合作請聯繫: artistes@weilamanner.com

not uniform 在 The Thirsty Sisters Youtube 的最佳解答
If you are ever in a situation where your modesty was being compromised, here are some links:
https://www.aware.org.sg/
https://singaporelegaladvice.com/law-articles/free-legal-clinics/
Listen to us on Spotify: https://open.spotify.com/show/5yx8txjfb7dMkosumEv6lQ?si=LGRX8wegS9SiFZJ1j7plGA
We need to start a conversation about the issue of sexual harassment and who better than our Thirsty Sisters. In this no holds barred podcast, they discuss several case studies of recent convictions of sexual harassment and assault, and how it is paramount we do better as a society.
06:07 Case Study #1: Police Staff Sergeant Molests Female Colleague
11:08 Case Study #2: NUS Student Molests Female on the Train
16:56 Case Study #3: NUS Ex Senior Lecturer Molest Students in the Campus Bus
20:43 Case Study #4: Doctor Gropes Patient at Work
32:57 Struggles Victims Go Through To Get Justice
Sources:
Police officer fined for molesting female colleague while on duty:
https://www.channelnewsasia.com/news/singapore/police-officer-fined-molest-female-colleague-duty-12620616
Undergraduate who molested woman on train jailed after probation sentence overturned:
https://sg.news.yahoo.com/undergraduate-who-molested-woman-on-train-jailed-after-probation-sentence-overturned-031206918.html
Ex-NUS senior lecturer jailed 14 weeks for rubbing against undergrad on campus bus:
https://www.straitstimes.com/singapore/courts-crime/nus-senior-lecturer-jailed-for-molesting-undergrad-on-crowded-campus-shuttle
Doctor charged with molesting woman at Mount Elizabeth Hospital, wants to claim trial:
https://www.channelnewsasia.com/news/singapore/doctor-charged-with-molesting-woman-at-mount-elizabeth-hospital-12405030#:~:text=Dr%20Yeo%20will%20return%20to,as%20he%20is%20above%2050.
‘Play play only, don’t tell’: Sec school teacher pleads guilty to molesting seven male students:
https://www.todayonline.com/singapore/play-play-only-dont-tell-sec-school-teacher-pleads-guilty-molesting-seven-male-students
Man jailed 7 months for molesting two schoolgirls on bus, MRT to Yishun:
https://www.todayonline.com/singapore/man-jailed-7-months-molesting-two-schoolgirls-bus-mrt-yishun
Man Jailed for touching boys on bus:
https://www.channelnewsasia.com/news/singapore/man-jailed-molest-boys-school-uniform-on-bus-12790690
GrabHitch driver who molested two female passengers in an hour gets 22 months’ jail:
https://www.todayonline.com/singapore/grabhitch-driver-who-molested-two-female-passengers-hour-gets-22-months-jail?cid=h3_referral_inarticlelinks_03092019_todayonline
Sylvia and Nina are not your typical influencers; they give it to you raw and real! Join them as they quench their never-ending thirst for wisdom, trends, success and men.
They explore hot and pressing issues you never thought you needed to know in this extremely in-depth podcast. Sisters, brothers and everyone in between or beyond; jump in and be thirsty!
Support us! https://www.patreon.com/noc. Join our Patreon to watch our videos early!
CLICK TO BE A THIRSTY SISTER
https://www.youtube.com/thethirstysisters
FOLLOW
https://www.instagram.com/thethirstysisterstts
http://www.noc.com.sg
anchor.fm/thethirstysisters
FIND THE TEAM ON INSTAGRAM
Find us on Instagram:
Sylvia - https://www.instagram.com/sylsylnoc
Nina - https://www.instagram.com/ninatsf
EMAIL
For business/brand features: thirstysisters@noc.com.sg.
For talent engagements: bella@noc.com.sg, sylvia@noc.com.sg.
ADDRESS
North View Bizhub
6 Yishun Industrial Street 1, #01-14
Singapore 768090
NOC PARTNERS
Cathay Photo - http://www.cathayphoto.com.sg/
MyRepublic - https://secure.myrepublic.com.sg/
Shunji Matsuo - http://www.shunjimatsuo.com.sg/
Flesh Imp - http://shop.fleshimp.com
Imba Interactive - https://www.facebook.com/IMBAinteractive
TopGear PC - https://www.topgearpc.com /
Bosch - https://www.bosch-home.com.sg/
Aftershock - https://www.aftershockpc.com/
The Thirsty Sisters STAFF
Co-Founder - Sylvia Chan
Co-Founder - Nina Tan
Producer - Nicole Liel
Assistant Director/Editor - Virus Tan
Crew Lead/Editor - Bryant Lee
Crew/Editor - Brandon Gwee
Crew/Editor - Charmaine Zheng
Crew/Editor - Priscilia Tan
Crew/Editor - Charmaine Zheng
Crew/Editor - Isaac Lim
Crew/Editor - Matt Mohamed
Crew/Motion Graphics Designer - Kher Chyn
Crew/Motion Graphics Designer - Bryan Seah
Crew/Motion Graphics Designer - Vanessa
Crew/Sound Engineer - Yu En
PSSST...
While we respect everyone's views and opinions, we hope you respect ours too. We are entertainers after all! So if you're going to be butt-hurt by our videos, simply click X :/ But for those who share our sense of humour, enjoy and watch on! Comment below with what you want to see next! :) Thank you!

not uniform 在 New Opportunities in Non Uniform Sampling - YouTube 的推薦與評價
... <看更多>