📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有47部Youtube影片,追蹤數超過338萬的網紅Tina Yong,也在其Youtube影片中提到,Join me as I try on shapewear from Skims, Spanx, ASOS & Cotton on. If you’re new here- welcome! don’t forget to click subscribe, so you don’t miss out...
cost control 在 IELTS Nguyễn Huyền Facebook 的最讚貼文
TỪ VỰNG CHỦ ĐỀ MONEY {kèm các THÀNH NGỮ, COLLOCATION rất hay}
🍄PHẦN THÀNH NGỮ
- money doesn’t grow on trees = said to warn someone to be careful how much money they spend, because there is only a limited amount: tiền không mọc từ trên cây → không nên tiêu pha quá nhiều tiền, vì tiền chỉ có hạn
- bread and butter = a job or activity that provides you with the money you need to live: kế sinh nhai, công việc giúp bạn trang trải cuộc sống
- bring home the bacon = supply material provision or support; earn a living: kiếm tiền về nuôi sống gia đình
- born with a silver spoon in your mouth = born into a very wealthy family: sinh ra đã ngậm thìa bạc → được sinh ra trong 1 gia đình giàu có
- a penny saved is a penny earned = is a way of saying that one should not waste money but should save it, even if little by little: một xu tiết kiệm cũng chính là một xu làm ra, không nên tiêu xài hoang phí
- an arm and a leg = a lot of money: đắt đỏ
- break the bank = cost too much: rất đắt, rất tốn kém
- easy money = money that is easily and sometimes dishonestly earned: tiền dễ kiếm, bạn không cần tốn quá nhiều công sức để kiếm
- foot the bill = to pay for something, esp. something expensive: chi trả ...
- on the breadline = very poor; with very little money to live on: cuộc sống rất khó khăn, nghèo khổ
- pay your (own) way = pay for everything yourself without relying on others: tự chi trả
🍄PHẦN TỪ VỰNG CHUNG
- to save for the future: tiết kiệm cho tương lai
- to save for retirement: tiết kiệm cho việc nghỉ hưu
- to get out of debt: thoát khỏi nợ nần
- a solid credit score: điểm tín dụng tốt
- long-term financial goals: mục tiêu tài chính dài hạn
- to take control of your finances: kiểm soát tài chính của bạn
- financial success: thành công tài chính
- long-term savings: tiết kiệm dài hạn
- to overspend: chi tiêu quá mức
- to set up a budget: lập ngân sách
- to make adjustments where necessary: thực hiện các điều chỉnh khi cần thiết
- your net income after taxes: thu nhập ròng của bạn sau thuế
- to pay off debt: trả nợ
- a huge financial burden: một gánh nặng tài chính lớn
- to become financially independent: trở nên độc lập về tài chính
- an emergency fund: quỹ cho các trường hợp khẩn cấp
- to cut your monthly expenses: cắt giảm chi phí hàng tháng của bạn
- high-interest credit card debt: nợ thẻ tín dụng lãi suất cao
- to make ends meet: kiếm sống, xoay sở cho đủ sống
- student loans: khoản vay cho sinh viên
👉PHẦN VÍ DỤ: Page mình xem tại đây nhé https://ielts-nguyenhuyen.com/tu-vung-chu-de-money/
Chúc page mình học tốt nè <3
#ieltsnguyenhuyen
cost control 在 Facebook 的精選貼文
【藥事知多D】抗流感藥知多D:Oseltamivir、Zanamivir
在東方文化裡,時間是一個非常重要的概念。
不論是孔子的「逝者如斯夫!不舍晝夜(《論語.子罕》)」、范蠡的「時不至,不可強生;事不究,不可強成(《國語.越語下》)」還是項羽的「時不利兮騅不逝(《垓下歌》)」,字裡行間總是表達對時間的感慨。
除此之外,《聖經.傳道書》也說:
凡事都有定期,天下萬務都有定時:生有時,死有時。栽種有時,拔出所栽種的也有時。殺戮有時,醫治有時……(第3章1至3節)
好!停!說到這裡,便夠了。
對!在相當程度上,「醫治有時」是有幾分道理的。
常言道:「時間就是金錢。」在用藥上,時間就是藥效,例如Oseltamivir、Zanamivir。
首先在藥理上,Oseltamivir、Zanamivir是一種神經氨酸酶抑制劑(Neuraminidase Inhibitor),沒有神經氨酸酶(Neuraminidase),便可能會妨礙病毒從受感染細胞裡釋放出來,達到抗病毒的效果,一般主要適用於KO甲型流感病毒(Influenza A)、乙型流感病毒(Influenza B)。
不過這兩種抗流感藥有一個弱點,便是「時間」。
簡單說,時間拖得愈久,藥效便會愈差。
所以重點是「搶時間」。
在用法上,一般建議愈早愈有效,最好在流行性感冒(俗稱「流感」)冒起後12小時內服用。[1]
實際上,在感到流感開始冒起後48小時內服用,Oseltamivir、Zanamivir或許能夠縮短病程,大約1天。[2]
看到這裡,看倌可能會說:
「唓……藥罐子,原來服藥還只不過是能夠縮短大約1天的病程,又有何用?」
誠然在大部分人眼裡,這一天或許可能算不上什麼……說真的,眨一眨眼又一天了,何足道哉!不過這一天往往足以改善用藥者的生活質素,甚至減低流感所帶來的社會成本(Societal Cost)。
舉例說,理論上,病少一天,便請少一天病假,自然便可能會減少流感所帶來的經濟損失。
除此之外,Oseltamivir、Zanamivir還可能會減少抗生素的整體使用率、下呼吸道併發症(例如支氣管炎(Bronchitis)、肺炎(Pneumonia))。[3][4]
所以這一天往往顯得非常重要。
再說香港人秒秒鐘幾十萬上落,真的可謂「一寸光陰一寸金。」
單是看香港交易所(簡稱「港交所」)停市一天對股市、股民的影響,便可見一斑。
(如欲了解更多用藥資訊,歡迎看看「小小藥罐子」網誌。)
💊💊💊💊💊💊💊
BLOG➡️http://pegashadraymak.blogspot.com/
IG➡️https://www.instagram.com/pegashadraymak/
YT➡️https://www.youtube.com/channel/UCQOMojMd6q7XnESMWwldPhQ
📕📕📕📕📕📕📕
著作➡️藥事知多D、用藥知多D、藥房事件簿、家居用藥攻略(各大書店有售)
Reference:
1. Aoki FY, Macleod MD, Paggiaro P, et al. Early administration of oral oseltamivir increases the benefits of influenza treatment. J Antimicrob Chemother. 2003;51(1):123-129.
2. Smith NM, Bresee JS, Shay DK, et al. Prevention and control of influenza: Recommendations of the Advisory Committee on Immunization Practices (ACIP). MMWR Recomm Rep. 2006;55(RR-10):1-42.
3. Kaiser L, Wat C, Mills T, et al. Impact of oseltamivir treatment on influenza-related lower respiratory tract complications and hospitalizations. Arch Intern Med. 2003;163(14):1667-1672.
4. Kaiser L, Keene ON, Hammond JM, et al. Impact of zanamivir on antibiotic use for respiratory events following acute influenza in adolescents and adults. Arch Intern Med. 2000;160(21):3234-3240.
cost control 在 Tina Yong Youtube 的最讚貼文
Join me as I try on shapewear from Skims, Spanx, ASOS & Cotton on. If you’re new here- welcome! don’t forget to click subscribe, so you don’t miss out on future uploads ? https://bit.ly/2JFCtDr
Follow me: https://www.instagram.com/tina_yong/
My White dress in the beginning https://go.magik.ly/ml/15n7p/
Skims
SCULPTING BRA https://shopstyle.it/l/bsuMj
CORE CONTROL BRIEF https://shopstyle.it/l/bsuNJ
SHEER SCULPT SHORT https://shopstyle.it/l/bsuNK
SCULPTING BODYSUIT MID THIGH W. OPEN GUSSET https://shopstyle.it/l/bsuNL
ASOS DESIGN padded bum enhancing anti-chafing shorts in black
https://go.magik.ly/ml/15m9g/
Spanx Suit Your Fancy Low Back Mid Thigh Smoothing Body in beige https://go.magik.ly/ml/15m9l/
Cotton On
Smoother and shaper high waisted short
https://go.magik.ly/ml/15m9n/
Go Figure Smooth Bodysuit
https://go.magik.ly/ml/15m9m/
*This video is not sponsored. Some links above are affiliate links, which means I make a small amount if you choose to buy the products. This does not cost you any extra, but it’s a great way to help support my channel.
**********************
Shop my Lashes https://petitecosmetics.com
[Get 20% off using code TINA20]
Shop my Bags & Accessories https://markandscribe.com
cost control 在 MONGABONG Youtube 的精選貼文
Created this sweet pink angelic look for Valentine’s Day this year! ? I wanted something a little more natural, not too over the top, and focusing on a radiant glowy base. If you’re prefer something more fancy, just opt for a bolder pink / red lip and you’re good to go ?
Soak in the season of LOVE and a wonderful Valentine’s Day loves!! ❤️
Let me know what you think of this look, or if you have any other makeup look / videos ideas you’ll like me to try out, leave them down in the comments box down below! ✨
? Beginner- friendly Easy curls with a hair straightener : https://www.youtube.com/watch?v=7OeNCnHbhmE
? 2020 Valentine’s Day Makeup : https://www.youtube.com/watch?v=RH9Hdp68OD8
PRODUCTS MENTIONED:
? Abib Hydration Water Gel
https://shopee.prf.hn/l/7gpRlk1
? Neutrogena Hydro Boost Water Gel
https://shopee.prf.hn/l/7AvJo15
? Kate Tokyo Colour Control Base
https://shopee.prf.hn/l/ryjmPlj
? Abib Hydration Cushion Compact #22
https://shopee.prf.hn/l/7Bv5MaG
? Nars Radiant Creamy Concealer #Vanilla
https://shopee.prf.hn/l/7YENDQ2
? It Cosmetics Heavenly Luxe Complexion Perfection Brush #7
https://bit.ly/3jzC7hb
? Cosme Decorte Marcel Wanders Powder
https://bit.ly/36UCtKf
? Fenty Beauty Brow MVP Ultra Fine Brow Pencil & Styler #MediumBrown
https://bit.ly/3q7B4Yk
? Sunnies Face Life Brow Grooming Gel #WarmBrown
https://bit.ly/3aLYvzU
? Clinique Cheek Pop #PancyPop
https://shopee.prf.hn/l/KmoVEa1
?3CE Blush Blusher #LastTime
https://shopee.prf.hn/l/6WLGxwg
? Peri Pera V-Shading #01 Almond Brown
https://shopee.prf.hn/l/KL9An0L
? Etude House Play Colour Eyes Rose Wine Palette
https://shopee.prf.hn/l/6Z8Z9Rb
? The Face Shop FMGT Ink Proof Brush Pen Liner #Brown
https://bit.ly/36YFN77
? YSL Rouge Volupté Shine Lipstick Balm #124 Rose Loulou
https://seph.me/3706sjY
? Jill Stuart Birth Jem Gloss #04 Diamond Bomb
https://bit.ly/3cVWnrV
? Clinique Lash Power Mascara
https://shopee.prf.hn/l/64dP40q
? Charlotte Tilbury Filmstar Bronze & Glow
https://bit.ly/36Zc9OV
--------------------------------------------------------------------------------------------------------------------------------------------------------------
FOLLOW ME
► Instagram: http://instagram.com/mongabong
► TikTok: www.tiktok.com/@mongabong
► Snapchat: @mongabong
► Blog: www.mongabong.com
► Email: hello@mongabong.com
FAQ
Hello! My name is Mong Chin and I'm from sunny Singapore. I am 1.63m and I am Singaporean Chinese. I speak English, Mandarin and am currently learning Korean in my free time. I love all things beauty and fashion, and I also like to share my life here. I hope you guys enjoy watching my videos!
DISCLAIMER
This video is not sponsored. Some of the links above are affiliate links, which means I may earn a small fee if a sale goes through them. It does not cost you any extra and it helps to support my lil' channel so i can continue creating content for you all ?
cost control 在 MONGABONG Youtube 的最讚貼文
I’ve been obsessed with True Beauty's Lim Ju-Kyeong’s makeup and styling that I decided to recreate this look for you guys! ? It's a super cute yet effortless, no makeup-makeup look that you can wear everyday, even to school.
??♀️ if you watched True Beauty! Are you #TeamSooho or #TeamSeoJun? HEHE leave it in the comments?
Also let me know how I fared in this transformation and what other looks you’ll like to see next in the comments down below ? Can’t wait for the final episode tonight omg!!!
My other K-Drama inspired looks:
??It’s okay not to be okay Ko Mun Yeong - https://www.youtube.com/watch?v=xKyX2ur51CE
??Hotel Del Luna 호텔 델루나 IU Jang Man Weol Cover Makeup - https://www.youtube.com/watch?v=NAgQg...
?? Hwyugi Korean Odyssey Jin Sun Mi (Samjang) makeup - https://www.youtube.com/watch?v=IKgEn...
??Yoon So Ah / Shin Se Kyung (Bride of the Water God) Inspired Makeup -
https://www.youtube.com/watch?v=czVcB...
PRODUCTS MENTIONED:
? Abib Heartleaf Toner Skin Booster
https://shopee.prf.hn/l/K9NOX1L
? Abib Heartleaf Essence Calming Pump
https://shopee.prf.hn/l/7JGeNWW
? Origins Ginzing Into The Glow Brightening Serum
https://shopee.prf.hn/l/62Gapq0
? Skin Inc Pure Deep Sea Hydrating Mask
https://shopee.prf.hn/l/62GMnXb
?(alternative) COSRX Ultimate Nourishing Rice Overnight Spa Mask
https://shopee.prf.hn/l/6PGlWMl
? La Roche Posay- Uvidea Tone Up Light Cream SPF50+
https://shopee.prf.hn/l/78Yv5gJ
? Kate Tokyo Skin Colour Control Base Lavender SPF19PA++
https://shopee.prf.hn/l/rd9eY14
? Kate Tokyo Skin Colour Control Base Pink SPF20PA++
https://shopee.prf.hn/l/rd9eY14
? Lancôme Absolue Cushion
https://bit.ly/2O4CnJs
?(alternative) Abib Hydration Cushion
https://shopee.prf.hn/l/75dqo9g
? Cosme Decorte Loose Face Powder
https://shopee.prf.hn/l/7oo3E9W
?(alternative) Innisfree No Sebum Moisture Powder
https://shopee.prf.hn/l/Kmo10J1
? Hour Glass Ambient Lighting Palette
https://bit.ly/3pLMgcQ
? Fenty Beauty Brow MVP Ultra fine brow pencil and styler #MediumBrown
https://bit.ly/3cDYy3i
?(alternative) EXCEL Powder & Pencil Eyebrow EX
https://shopee.prf.hn/l/KMEkZv3
? Etude House Volumize My Brows #LightBrown
https://shopee.prf.hn/l/rGE90PO
? One/Size Patrick Starrr Visionary Eyeshadow Palette
https://bit.ly/3pZHGaU
?(alternative) ETUDE Play Color Eyes (Palettes for the seasons)
https://shopee.prf.hn/l/KzyE1R9
? Maybelline Line Tattoo Crayon Pen #Brown
https://shopee.prf.hn/l/KX9AVGD
?PeriPera Ink V-Shading #AlmondBrown
https://shopee.prf.hn/l/6qO92od
? Nars Blush #Behave
https://bit.ly/3avOl6u
?(alternative) 3CE BLUSH BLUSHER #LastTime
https://shopee.prf.hn/l/6b1eYLq
? Shu Uemura Rough Unlimited Liquid Lacquer #CR03
https://bit.ly/39JXV6k
?(alternative) rom&nd (romand) Glasting Water Tint 4g #07 Pink Valley
https://shopee.prf.hn/l/7YEjY0Y
? Dyson Supersonic
https://bit.ly/36JbFN0
? Create Ion Hair Curler 32mm
https://shopee.prf.hn/l/7xNEx5z
? GHD Platinum+ Take Control Now Collection Styler
https://shopee.prf.hn/l/7gpNYyj
? Hair Root Brush (my stylist @jay.ang got this for me)
OUTFIT
? Shirt - Monologue in Seoul
? Cardigan - GG5
https://bit.ly/3pOT89u
? Skirt - Seoul (very sad can’t travel now but you can easily find this on Taobao)
--------------------------------------------------------------------------------------------------------------------------------------------------------------
FOLLOW ME
► Instagram: http://instagram.com/mongabong
► TikTok: www.tiktok.com/@mongabong
► Snapchat: @mongabong
► Blog: www.mongabong.com
► Email: hello@mongabong.com
FAQ
Hello! My name is Mong Chin and I'm from sunny Singapore. I am 1.63m and I am Singaporean Chinese. I speak English, Mandarin and am currently learning Korean in my free time. I love all things beauty and fashion, and I also like to share my life here. I hope you guys enjoy watching my videos!
DISCLAIMER
This video is not sponsored. Some of the links above are affiliate links, which means I may earn a small fee if a sale goes through them. It does not cost you any extra and it helps to support my lil' channel so i can continue creating content for you all ?