📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有36部Youtube影片,追蹤數超過0的網紅FERNTUBE (Fernanda Ly),也在其Youtube影片中提到,(Giveaway info is at the bottom) Today we celebrate 10k subs with a Vivienne Westwood sample sale video that I've been meaning to post 🌟 I may or may...
「not choose at random」的推薦目錄:
- 關於not choose at random 在 Taipei Ethereum Meetup Facebook 的精選貼文
- 關於not choose at random 在 hangryjoobert Facebook 的最佳貼文
- 關於not choose at random 在 Facebook 的精選貼文
- 關於not choose at random 在 FERNTUBE (Fernanda Ly) Youtube 的最佳貼文
- 關於not choose at random 在 Shiney Youtube 的精選貼文
- 關於not choose at random 在 Shiney Youtube 的最讚貼文
not choose at random 在 hangryjoobert Facebook 的最佳貼文
เค้กแซลม่อนจากธรรมชาติซีฟู้ด สดแน่นมากค่า
Looking to make a grand entrance into this weekend at home with your family? Make way for this #sushicake loaded with salmon and all the Japanese goodies inside from Thammachart Seafood! It's huge (with options of 1 or 2 pound to choose from), it's super filing (with sushi rice, wakame, tamago yaki, and crab stick salad inside), and the salmon on top is surprisingly quite very fresh and nice! Warning, this item is way more stomach-filling than it may seem in the pictures, and it's perfect for a birthday party, a celebration, or just a random party at home with your loved ones (cause why not!)
มองหาไอเท็มฉลองสุดสัปดาห์กับครอบครัวอยู่หรือเปล่าค๊าา โปรดหลีกทางให้แก่ #เค้กแซลมอน สุดอลังการแต่ราคาสบายเป๋าจากร้าน#ธรรมชาติซีฟู้ด เลยค่ะแม่ จะบอกว่ามันเบิ้มมาก (มีแบบ 1 และ 2 ปอนด์ให้เลือก) มันอิ่มมาก (ด้านในมีข้าวซูชิ สาหร่ายวากาเมะ ไข่หวาน และปูอัดแบบแน่นๆจุกๆอีก) และแซลมอนที่ห่อมาด้านบนนี่ให้มาแบบไม่หวง แถมยังคุณภาพดี สดโอเคเลยนะ ขอเตือนก่อนว่าตัวเค้กม่อนนี้อิ่มกว่าที่ดูจากในภาพมากนะทุกคน เพอร์เฟคสำหรับจัดงานวันเกิด ฉลองวันสำคัญ หรือจะมาฟินที่บ้านโดยไม่ต้องมีเหตุก็ได้ไม่ว่ากันเด้ออ!
Food: ❤️❤️❤️❤️
Ambience: N/A
Service: N/A
Area: delivery across bangkok
Price:
- 1 pound: 590 THB
- 2 pound: 990 THB
.
.
.
.
.
#thammachartseafood #ธรรมชาติซีฟู้ด #ซูชิ #แซลมอน #ปลาส้ม #ซาชิมิ #แซลม่อน #แซลมอนซาซิมิ #อาหารญี่ปุ่น #เค้กมินิมอล #ปลาแซลมอน #อร่อยไปแดก #อร่อยไปเเดก #กินข้าวกัน #กินไรดี #กักตัวอยู่บ้าน #workfromhome #เมนูกักตัว #รีวิวอาหาร
not choose at random 在 Facebook 的精選貼文
#Updates #Robynnblogs
The world really has evolved several stages since 2020, and also since the beginning of my career- and that’s the beauty of it all. Nothings permanent, everything changes and newer, more exciting things keep coming into the mix.
Tomorrow my baby will turn 6 months. What a massive milestone, for her and for myself. As I am learning everyday to be a better mother, I am also learning to become a stronger me. I have been wanting to update fans and friends on how I am doing - and yet every time I try, I just feel like “oh gosh. Where do I even start?” And before that thought process is over, I would be busy either feeding my baby, changing a diaper, soothing her, or putting her to sleep.
The first few months of my baby’s life felt like it flew by so quickly yet at the same time pre-baby feels like a lifetime ago - everything in my world has shifted. My whole focus was her - I was breastfeeding, (which, by the way, is HEAPS harder than giving birth), making sure she’s eating well, sleeping well, and pooping well. And, understandably, paranoid about any kind of germs in the house. There was no difference between day and night, it’s just wake time and sleep time. It made no difference for me what day of the week it was, what weather it was, what’s happening with my industry, or with the world other than the daily Covid news, because I just needed to stay home make sure that my little newborn is far far far away from covid. I barely saw friends, and hadn’t eaten in a restaurant for north of half a year. As I took care of her, I barely had time to wash my own face, go to the bathroom, or sleep for a long stretch of time. I also didn’t have enough breastmilk, so I would sit there and try to pump the life out of me, just so I could provide half of a meal for my baby. I tried everything - but I do know that low supply isn’t uncommon. So- as glamorous as mom life can appear to be on social media, don’t be fooled. It’s humbling, but it’s also life-altering and the most rewarding thing I’ve ever done.
Emotionally, I’ve been so over the moon and happy. I enjoy spending time with my newborn baby, she makes me giggle and smile - even though I wish my mother was here to share old baby stories of me, and experience all of this together. But having a daughter really makes you feel more connected to your mother on a completely different level - I just know she’s happy and proud of me from up above. I’ve taught her how to semi-feed herself, how to fall asleep by herself, teaching her still how to roll, sit, and semi-stand (crazy!!), and I’ve played her tunes on my guitar like she’s the only fan in my fan club.
I also consider myself blessed that I never had issues with postpartum depression, despite suffering from mommy’s wrist. I had an amazing relationship with my 陪月/月嫂 who helped me immensely more than words can say. I have not been able to see my side of the family for over a year, but I’m blessed to have amazing in-laws and fellow mommy friends to share experiences with.
Nothing has been easy, but I am the most grateful for my husband - he was always by my side when I needed him. We change diapers together, we bathe our daughter, we sing to her together, and read bedtime stories to her together. I can safely say, that I’m MUCH happier than when I was towards the end of my music label contract. There have been some dark years there.
Hitting 6 months is a big deal for me. I can safely pat myself on my back and reminisce on THE single most biggest achievement of my life, my daughter. Obviously, 6 months is not long in the grand scheme of things, ie. her entire life ahead, but it is a big milestone for me mentally, and finally I feel it’s time to really focus on my own personally healing. I completely lost myself in taking care of her, and yet I felt the most alive and the most needed - and I found a new me in the process. It’s a beautiful kind of chaos and I embraced all of it. But yes, now it’s time for me again. finally.
Hitting this 6 month mark, I have decided to now wean from breastfeeding, take care of my body better, drink some wine, and write more songs for real. (If my daughter allows, lol). I am choosing to give myself some more me-time, read a book, get my nails done, and eventually get a haircut too. And.. start to think about dieting and training. Moms don’t get enough credit for deciding consciously to not slim down yet because they gotta breastfeed. But- with that said, all moms have their own struggles that no one knows of, so never judge!
A part of the stress that comes with social media sometimes, is actually comments on moms’ sizes, even praises of “wow you slimmed down fast!” As though that’s the most important thing of all. The toxic culture pains me and I just know it’s not the point. For me, it really was a conscious decision, just to be a mother first, above all else, at least for these first six months of her little life. And looking at her, strong, happy and healthy, I am truly so so proud of her for her growth and development.
And finally.. I’m finally ready to think about myself again as a musician. I know I’m lucky to be able to have a choice of being with her for 6 months; I count my blessings everyday. But as songwriting wheels become rustier, and as the industry evolves, I’m quite frankly not sure yet what a singer-songwriter mom looks like. I struggle to name artists in the Chinese speaking world that I could reference from - but I promise I’ll continue to bring music to those ears that still choose to listen.
I still hope that one day - little Naomi can see mama on stage. Looking down at her as she sleeps, I always imagine what she would be like as she grows up - and I hope that one day she will be able to pursue what she loves to do and focus on the truly meaningful things in life.
Thank you for reading through this thinking-out-loud random catch-up session blog thing. I’m just so glad I survived 6 months of motherhood. This stuff ain’t easy! Sending love and thank you all for the support, as always. More updates later!
xRobynn
#updates #robynnblogs
not choose at random 在 FERNTUBE (Fernanda Ly) Youtube 的最佳貼文
(Giveaway info is at the bottom)
Today we celebrate 10k subs with a Vivienne Westwood sample sale video that I've been meaning to post 🌟
I may or may not have been waiting for this milestone in order to do so 👀
I previously asked if everyone was open to a giveaway and I'm so excited to hold one now! The names of the prizes are also below in case you want to buy them yourself hahaha
Fun fact: The night before was when I dislocated my knee, but as a big fan and collector of VW I couldn't miss this sale. Pretty sure standing in line is what made my knee worse.... The few weeks in an immobiliser was worth it for this 🤗
I've really enjoyed being on YouTube, so thank you for your support thus far! Tbh I wasn't expecting to keep at it for so long lol
It's been fun learning how to edit videos and images too. I'm aware there are many things I could improve on and things I could nitpick at, but I feel like I've come a long way from my first upload 9 months ago 🥸
Again, thank you so much for your continued support in watching, commenting, and liking my videos. It means the world to me ❤
ーーーーーーー
#ferntube #viviennewestwood #giveaway
✩ Instagram: @warukatta
✩ Email: ferntube22@gmail.com
Please contact my agencies in regards to model work
ーーーーーーー
✩ Songs:
Waves - Fiji Blue (https://thmatc.co/?l=518C9DB2)
Lovely Day - VirgoZilla Beatz (https://thmatc.co/?l=184FE7FC/)
✩ Subtitle file: (https://drive.google.com/file/d/1GHCjMd_s-ciGbpcVa_p1W8XlnsnA0O6s/view?usp=sharing)
*** As Youtube has unfortunately discontinued community contributions, here is the script for anyone still willing to do subs for other languages. If you replace the english text with your language and email me the file, I'll be more than happy to upload it for everyone to see. Thank you for your helpful contributions until now!
✩ FTC: This giveaway is not sponsored by Vivienne Westwood, YouTube, nor any other company and all moneys spent is my own.
ーーーーーーー
Ferntube's 10k Subscriber Giveaway ❤️❤️❤️
Comment to win a pair of Vivienne Westwood earrings in celebration of 10k subs!
I want to share my happiness by giving two(!) subscribers the chance to win a pair of earrings each!
🌎 Giveaway is open worldwide 🌎
PRIZES:
✩✩ Vivienne Westwood 'Sorada' Orb Earrings (Crystal on Rhodium) ✩✩
✩✩ Vivienne Westwood 'Rosemary' Small Earrings (Brass) ✩✩
HOW TO WIN:
Leave a comment on this video
That's it
Please be sure you're subscribed to my YouTube (I'll be checking!)
If you are under 18 years old, please have parental permission before commenting.
Only one entry per person; multiple entries/ comments will not be counted.
I'll use a random number generator to choose two winning comments so everything stays fair ❤️
Giveaway begins 02/03/2021 upon upload and closes midnight (Eastern Standard Time) of 22/03/2021
Winners must message me within 48 hours of contact to claim prizes, if not, I will have the rng choose another comment.
not choose at random 在 Shiney Youtube 的精選貼文
Watch Dogs: Legion
ซื้อเกมได้ที่ https://store.epicgames.com/legendauser/watch-dogs-legion
Watch Dogs: Legion is an action-adventure game played from a third-person perspective, and takes place within an open world setting based upon London, which can be explored either on foot - utilizing parkour moves - vehicles, or fast-travelling via the city's Underground stations. The game is composed of several missions, including those that progress the main story, liberation missions aimed at freeing the city's boroughs featured in the setting, recruitment missions for new playable characters, and various side-activities, with players able to freely pursue a mission or activity, or explore the city for secrets and collectibles. Each mission's objectives can be handled via one or several different approaches: an open-combat approach utilizing a variety of weapons; a stealth approach utilizing the environment to avoid detection and monitoring enemy patterns; or a hacking approach using any hackable object to subdue enemies with traps or distractions, while seeking out objectives via cameras and remotely accessing them. Combat includes a mixture of gun fights - involving lethal and non-lethal fire-arms - and hand-to-hand combat moves, with enemies making use of different methods depending on how the player acts against them in combat (i.e. a guard hit with a punch will use melee attacks). Players can be pursued by enemies when escaping, including hostile drones, but can lose them by utilizing hack-able environmental objects (i.e. vents) and avoiding line of sight with pursuers.
Unlike previous games in the series, Legion features the ability to use multiple characters during a playthrough, each of whom can be recruited from around the game's setting. While the player must choose a character to begin with after the story's prologue chapter, others may be recruited upon completing the initial story missions of the game from anywhere around the game's setting, which can also include those working for hostile factions. Those recruited become operatives that the player can freely switch to at any time, as well as customize with different clothing options, with each recruit-able character maintaining their own lifestyle and occupation when not active (i.e. spending time drinking at a pub). Each character that can be recruited have different traits and skills, based upon their background - a spy operative has access to a silenced pistol and can summon a special spy vehicle to travel around with, armed with rockets; a hooligan operative can summon in friends to help in a fist-fight; a builder operative can make use of large drones for heavy-lifting and a nail-gun for combat; while an "adrenaline junkie" operative can deal more damage, but risk the possibility of being knocked out/dying at any random moments. Operatives can gain experience when used by the player, which allows them to gain additional skills and abilities to improve them, with the player able to provide additional upgrades for all character by spending "tech points" - a collectible scattered around the city, which can be spent on weapon and gadget upgrades.
All potential recruits have an additional statistic, which details whether they can be recruited when approached - their thoughts on DedSec. Some recruits may not join if either they favour those that oppose them (such as a hostile faction), if the player has a character in their roster whom they hate or if DedSec did something to harm another NPC they have good relations with. If a recruit can be brought in, players will be required to complete a mission from them related to a problem they need resolving. An example of such a mission would be helping someone determine why they are being constantly spied on more frequently of late working as a vigilante in shutting down a criminal operation they seek to disrupt. Any character that can be recruited, can be killed during a playthrough by criminal gangs or law enforcement, and thus be permanently removed from the player's roster of playable characters, provided the player has the permadeath option enabled; if not, the character is merely arrested, and can be simply rescued by another operative. If the player loses all their characters from death or arrest, the game ends.
The online component of the game would be introduced through a free post-launch update in December 2020. Players can also join a team of up to four players in cooperative gameplay, sharing progression between single-player and multiplayer modes. They can also access Tactical Ops, which are co-operative missions designed for 4 players, or simply explore London together. The asymmetrical multiplayer mode Invasion would also return. The game also features a competitive multiplayer mode named "Spiderbot Arena" in which players assumes control of a gadget named spiderbot and compete against each other in free for all matches.
not choose at random 在 Shiney Youtube 的最讚貼文
Watch Dogs: Legion
ซื้อเกมได้ที่ https://store.epicgames.com/legendauser/watch-dogs-legion
Watch Dogs: Legion is an action-adventure game played from a third-person perspective, and takes place within an open world setting based upon London, which can be explored either on foot - utilizing parkour moves - vehicles, or fast-travelling via the city's Underground stations. The game is composed of several missions, including those that progress the main story, liberation missions aimed at freeing the city's boroughs featured in the setting, recruitment missions for new playable characters, and various side-activities, with players able to freely pursue a mission or activity, or explore the city for secrets and collectibles. Each mission's objectives can be handled via one or several different approaches: an open-combat approach utilizing a variety of weapons; a stealth approach utilizing the environment to avoid detection and monitoring enemy patterns; or a hacking approach using any hackable object to subdue enemies with traps or distractions, while seeking out objectives via cameras and remotely accessing them. Combat includes a mixture of gun fights - involving lethal and non-lethal fire-arms - and hand-to-hand combat moves, with enemies making use of different methods depending on how the player acts against them in combat (i.e. a guard hit with a punch will use melee attacks). Players can be pursued by enemies when escaping, including hostile drones, but can lose them by utilizing hack-able environmental objects (i.e. vents) and avoiding line of sight with pursuers.
Unlike previous games in the series, Legion features the ability to use multiple characters during a playthrough, each of whom can be recruited from around the game's setting. While the player must choose a character to begin with after the story's prologue chapter, others may be recruited upon completing the initial story missions of the game from anywhere around the game's setting, which can also include those working for hostile factions. Those recruited become operatives that the player can freely switch to at any time, as well as customize with different clothing options, with each recruit-able character maintaining their own lifestyle and occupation when not active (i.e. spending time drinking at a pub). Each character that can be recruited have different traits and skills, based upon their background - a spy operative has access to a silenced pistol and can summon a special spy vehicle to travel around with, armed with rockets; a hooligan operative can summon in friends to help in a fist-fight; a builder operative can make use of large drones for heavy-lifting and a nail-gun for combat; while an "adrenaline junkie" operative can deal more damage, but risk the possibility of being knocked out/dying at any random moments. Operatives can gain experience when used by the player, which allows them to gain additional skills and abilities to improve them, with the player able to provide additional upgrades for all character by spending "tech points" - a collectible scattered around the city, which can be spent on weapon and gadget upgrades.
All potential recruits have an additional statistic, which details whether they can be recruited when approached - their thoughts on DedSec. Some recruits may not join if either they favour those that oppose them (such as a hostile faction), if the player has a character in their roster whom they hate or if DedSec did something to harm another NPC they have good relations with. If a recruit can be brought in, players will be required to complete a mission from them related to a problem they need resolving. An example of such a mission would be helping someone determine why they are being constantly spied on more frequently of late working as a vigilante in shutting down a criminal operation they seek to disrupt. Any character that can be recruited, can be killed during a playthrough by criminal gangs or law enforcement, and thus be permanently removed from the player's roster of playable characters, provided the player has the permadeath option enabled; if not, the character is merely arrested, and can be simply rescued by another operative. If the player loses all their characters from death or arrest, the game ends.
The online component of the game would be introduced through a free post-launch update in December 2020. Players can also join a team of up to four players in cooperative gameplay, sharing progression between single-player and multiplayer modes. They can also access Tactical Ops, which are co-operative missions designed for 4 players, or simply explore London together. The asymmetrical multiplayer mode Invasion would also return. The game also features a competitive multiplayer mode named "Spiderbot Arena" in which players assumes control of a gadget named spiderbot and compete against each other in free for all matches.