📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有13部Youtube影片,追蹤數超過30萬的網紅Micaela ミカエラ,也在其Youtube影片中提到,Although Japan is not currently on any sort of lockdown or strict order to stay indoors, I think we are all starting to realize that we need to take m...
「bring convenience」的推薦目錄:
- 關於bring convenience 在 Taipei Ethereum Meetup Facebook 的最佳貼文
- 關於bring convenience 在 IELTS Nguyễn Huyền Facebook 的最讚貼文
- 關於bring convenience 在 Lau Kin Lam - 林仔 Facebook 的最佳解答
- 關於bring convenience 在 Micaela ミカエラ Youtube 的最讚貼文
- 關於bring convenience 在 ochikeron Youtube 的最讚貼文
- 關於bring convenience 在 Spice N' Pans Youtube 的最佳貼文
- 關於bring convenience 在 没有照片描述。 - Facebook - 登录或注册 的評價
- 關於bring convenience 在 Microwave - Pinterest 的評價
- 關於bring convenience 在 China-Laos Railway to bring convenience to trade, travel 的評價
bring convenience 在 IELTS Nguyễn Huyền Facebook 的最讚貼文
TỪ VỰNG IELTS CHỦ ĐỀ BOOKS AND FILMS
🎗PHẦN TỪ VỰNG
- a bookworm: một kẻ mọt sách
- to start reading at an early age: bắt đầu đọc sách từ khi còn nhỏ
- fairy tales: truyện cổ tích
- to develop imagination and creativity: phát triển tính tưởng tượng và sáng tạo
- bedtime stories: các câu chuyện kể vào giờ đi ngủ
- to promote brain development: kích thích sự phát triển của não bộ
- to reduce stress: giảm căng thẳng
- reading comprehension: việc đọc hiểu
- to prefer ebooks to paper books: thích sách điện tử hơn là sách giấy
- to bring a great deal of convenience: mang lại nhiều sự tiện lợi
- to be easily downloaded: dễ dàng tải về
- to make reading part of your routine: làm cho việc đọc sách trở thánh một phần trong thói quen của bạn
- to improve a child’s vocabulary: cải thiện vốn từ vựng của trẻ
- to be a great form of entertainment: là một hình thức giải trí tuyệt vời
- a thick book: một quyển sách dày
- to read a book from cover to cover: đọc 1 quyển sách từ đầu tới cuối
- a blockbuster: một bộ phim bom tấn
- to watch a documentary: xem một bộ phim tài liệu
- to spend … hours sitting in front of the TV: dành … giờ đồng hồ ngồi trước màn hình TV
- low-budget movies: các bộ phim có kinh phí thấp
- to contain violent scenes: chứa các cảnh bạo lực
- to widen their horizons: mở mang tầm nhìn
- to enrich their knowledge: làm giàu vốn kiến thức
PHẦN VÍ DỤ: Page mình xem tại đây nhé https://ielts-nguyenhuyen.com/tu-vung-ielts-books-and-films/
#ieltsnguyenhuyen
bring convenience 在 Lau Kin Lam - 林仔 Facebook 的最佳解答
【林仔優惠大放送】嗱唔好話唔醒你哋,用我專用code #LAMJAI85 喺 www.conven.cc 買嘢,即享全單八五折優惠,而購物滿HK$250,#香港 及 #澳門 訂單即免運費,仲唔即刻上掃貨?
#CONVEN
bring convenience 在 Micaela ミカエラ Youtube 的最讚貼文
Although Japan is not currently on any sort of lockdown or strict order to stay indoors, I think we are all starting to realize that we need to take matters into our own hands and self-isolate as much as possible. For those of you who are dealing with your first "crisis" in Japan, I wanted to provide a little bit of a guide to help you make sure you're as prepared as you can be, for spending time indoors.
-------------------------------------------------------------------------------------------------------------------------
●Curry
- Meats: Pork, Beef, or Chicken. Whatever you have.
- Vegetables: Potato, Onion, Carrot, Mushrooms, Spinach/Komatsuna/Kale, Asparagus, Sweet Potato, Pumpkin (Kabocha), Eggplant, Okura, Renkon (Lotus Root)
Quick Tutorial on How To Make Curry @ 4:53
●Instant Miso (for reference, this is the kind I usually buy https://www.amanofd.jp/amano/shop/goods/index.html?ggcd=B4741&cid=miso)
You can buy any kind, some instant miso comes with a paste, which some people may prefer but I like the freeze-dried type. It is said that certain nutrients are preserved when you freeze-dry vegetables, so I think they're a bit healthier.
●Cook Do (for reference: https://www.ajinomoto.co.jp/cookdo/lineup/)
These are usually found in the Chinese seasoning section of your Japanese supermarket (as the majority of the boxes are Chinese.) Similar simple-meal kits with Japanese recipes are sometimes stocked in the same aisle.
●Canned Tomatoes
- Good for curries (add one can of diced tomatoes to your curry to make it more tangy and acidic)
- Pasta (sautee veggies, garlic, onion, and bacon, add your diced tomatoes, stew, taste, and season, add to pasta)
- Soups (lightly sautee your favorite soup veggies in oil and garlic, pour diced tomatoes into the pot, then fill the empty tomato can with water and add one cube of soup stock of your choice, throw in your desired seasonings, bring to a boil and simmer. you can add rice, quinoa, gains, shredded chicken to make it a hearty meal.)
- Stews (for beef, lamb, and pork, I cut my vegetables large, season them first with cumin, curry spice, cinnamon, salt, pepper, paprika, etc to make a fragrant mix, then add tomatoes and water, and simmer until liquid has dissolved and the mixture is thick enough to be a stew.)
- Salsa (Use half a can, pulse in a mixer with red onion, cilantro, garlic, green pepper, red chiles, lemon, salt, pepper, and a bit of cumin for a more tex-mex flavor)
●Spices:
I didn't show them in the video but I actually prefer S&B's herb packets, you can see what they look like here:
https://www.sbotodoke.com/shop/c/cB51210/
Most supermarkets have them, and they are very versatile, cheap, and easy to use.
●Yakiniku Sauce:
You can choose any kind you like! When in doubt, the popular Yakiniku chain "Gyukaku" has a sauce in the supermarket that's pretty good. Use this on "grilled" and "charred" meats. Tastes great over rice. Make a "Yakiniku Bowl" with charred carrots, cabbage, onion, green pepper, and slices of beef or pork.
●Ponzu: I prefer Yuzu, but you won't be missing out on too much if they don't stock it. Regular Ponzu works. Use this on steamed veggies with lighter flavors, or in sautees with Asian veggies (bok choy with garlic topped with ponzu, baked white fish with salt and ponzu, or daikon and pork sauteed with ponzu is great!) Can be mixed with olive oil, salt, and pepper to make a salad dressing too!
●Veggies - Try to pick a few greens, and then one veggie of each color. I try to plan for one raw-green (for salads), one wilting-green (for soups and stir-fries), and one firm-green (for baking grilling) per shop.
Green: Lettuce, Baby Leaf, Spinach, Bok Choy, Komatsuna, Asparagus, Zucchini, Green Pepper, Kale, Cucumber, Cabbage, Avocado
Purple: Red Onion, Eggplant, Purple Turnip, Satsumaimo (Sweet Potato), Purple Cabbage (great for adding color).
Red: Tomatoes, Red Peppers, Beets, Beni Daikon (Red Radish)
Orange: Carrot, Pumpkin, Orange Pepper, Orange/Yellow Fruit Tomatoes
White: Daikon, Turnip, Cauliflower, Renkon (Lotus Root), Bean Sprouts, Potato, Onion, Sato-Imo, Yama-Imo,
Brown: Gobo (burdock root), Mushroom
●Buy & Freeze:
- A loaf of bread or two (Japanese bread tends to come in slices instead of loaves so buy accordingly.)
- Meats (Chicken Breasts are the most versatile AND cost-effective IMO.)
- Frozen Seafood (S&B has a paella seasoning! if you can find it, this is a nice way to utilize rice, veggies, and seafood)
- Frozen naughty snacks like pizza, dorayaki, frozen fried rice, emergency instant meals, etc can go here too.
●Pasta and Rice are good to have, but if you don't have a rice cooker in your apartment, you can buy a few microwavable instant-packs from your supermarket or convenience store and store those instead.
------------------------------------------------------------------------------------------------------------------
Let me know what you'd add! I'm out of space and can't write more :'(

bring convenience 在 ochikeron Youtube 的最讚貼文
In this video, I will show you how to make very basic Inarizushi with plain Sushi rice. Easy yet delicious, perfect for party, picnic, or any kind of event!
Inarizushi (Inari Sushi) is Sushi rice stuffed in tasty Aburaage (Fried Tofu pouches).
In Japan, Inarizushi can be widely found at restaurants, supermarkets, conbini (convenience stores), and etc... Sometimes store-bought ones are too sweet but this one is very mild. Homemade is the best 😉
You can also make Inarizushi with flavored rice:
https://youtu.be/lIj9H4KLLbY
Topping ideas:
https://youtu.be/7u8wzq0F5bM
Dashi Broth (Kayanoya Dashi) I used:
https://amzn.to/30XjISb
---------------------------------
How to Make Basic Inarizushi
Difficulty: Easy
Time: 1hr + cooling time
Number of servings: 20 pieces
Ingredients:
660g (1.5lb.) cooked Japanese rice (short-grain rice)
A
* 3 tbsp. rice vinegar
* 3 tbsp. sugar
* 1 tsp. salt
10 square Aburaage (deep-fried tofu pouches)
B
* 4 tbsp. soy sauce
* 4 tbsp. Mirin (sweet Sake)
* 4 tbsp. sugar
* 400ml Dashi broth
4 tbsp. roasted white sesame seeds
Directions:
1. Place the Aburaage on a cutting board and trace the Aburaage with a chopstick to make it easy to open. Cut into half and open. If you are using square Aburaage (deep-fried tofu pouches) cut diagonally into half to get 2 right-angled triangles. If you are using rectangular Aburaage, cut into half to get 2 squares.
2. Put Aburaage in boiling water for a minute to remove the excess oil. Drain in a strainer and wash with warm water. Stack up 3-4 pieces at a time, then press with your hands to drain well.
3. Put B and Aburaage in a pot, then bring to a boil. Turn the heat down to low and cover with an Otoshibuta or a wooden drop-lid (you can substitute it with with a sheet of aluminum foil and use any small lid or a plate as a weight if needed) and simmer for 20 minutes. Stop the heat and let them cool completely for a few hours or overnight is OK.
4. Make Sushi vinegar by mixing A (or use store-bought Sushi vinegar). Add the Sushi vinegar while the rice is hot and slice through the rice using a rice paddle to separate the grains. Mix sesame seeds in the Sushi rice. Divide the rice into 20 equal portions. Wet your hands and make small balls of Sushi rice.
5, Take a piece of Aburaage and lightly press with your hand to remove the excess liquid. Stuff a ball of Sushi rice and close the pouch. *Please see the video for details.
レシピ(日本語)
https://cooklabo.blogspot.com/2020/01/inarizushi.html
---------------------------------
Music by
YouTube Audio Library
Follow me on social media. If you have recreated any of my food, you can share some pictures #ochikeron. I am always happy to see them.
♥FOLLOW ME HERE♥
http://instagram.com/ochikeron/
https://www.facebook.com/ochikeron
https://plus.google.com/+ochikeron
http://twitter.com/ochikeron
♥My COOKBOOK available on Amazon Kindle♥
http://amzn.to/2EwR3ah
NO MORE hard copies... those who got one are lucky!
♥More Written Recipes are on my BLOG♥
http://createeathappy.blogspot.com/
♥My Recipe Posts in Japanese♥
http://cooklabo.blogspot.jp/
http://cookpad.com/ami
http://twitter.com/alohaforever
♥and of course PLEASE SUBSCRIBE♥
http://www.youtube.com/user/ochikeron?sub_confirmation=1

bring convenience 在 Spice N' Pans Youtube 的最佳貼文
These are the tastiest pressure cooked baby back ribs that Roland has ever made. If you love ribs, try this recipe instead of your typical barbecued (bbq) ribs. The flavour profile of these ribs will blow your mind. We have cooked these ribs both in an oven as well as a pressure cooker and we found that with pressure cooking, you can achieve the super tender fall-off-the-bone effect. Highly recommended! Fret not if you don't have a pressure cooker. You can still cook these yummilicious ribs in your oven or airfryer. You can use your stove-top pressure cooker to make these ribs too.
Hope you can recreate this yummy dish in the comfort of your home. Thanks for dropping by our channel.
Please subscribe to stay tuned for more of our home cooking videos.
Follow us on:
Youtube: www.youtube.com/spicenpans
Facebook www.facebook.com/spicenpans/
Instagram www.instagram/spicenpans
Blog: www.spicenpans.com
Chat with us! info@spicenpans.com
Thanks for watching! See you soon.
xoxo
Jamie
on behalf of Spice N’ Pans
Ingredients:
Makes about 8-10 ribs (serves 3 - 4 pax)
Part (1)
2 stalks of lemongrass (only white part)
30g of young ginger
5 cloves of garlic
5 pcs of shallots
A small handful of kaffir lime leaves (remove spine)
90g of palm sugar (can use brown or white sugar)
1/2 tbsp of chilli powder (optional)
1 tbsp of turmeric powder
1 tsp of coriander seed powder
1/2 tsp of nutmeg powder
1 tbsp of salt
125ml of kichap manis (Indonesian sweet soy sauce)
65ml of water
Part (2)
550g of ribs
Part (3)
Some cornstarch solution
Blend Part (1) into a marinade and use it to marinate Part (2) after you have scored it all over. Marinate the ribs for at least 2hrs or best overnight. Pressure cook the ribs for 30 mins or cook them in an oven or airfryer. If you’re cooking the ribs in an oven or airfryer, remove as much marinade from the ribs as possible before cooking. See cooking time below.
Once the ribs are done, bring the sauce to a boil and thicken it with Part (3). Thicken the sauce enough to coat the ribs well. Serve while the ribs are hot.
Cooking temperature in oven.
(A) Preheat oven at 180C for at least 20 mins
(B) 180C (356F) for 1hr
(C) 220C (428F) for 10 mins
If you’re using an airfryer, preheating is not necessary. Cook your ribs starting from Step (B).
===
If you like this recipe, you might like these too:
10 MIN EASY Thai Glass Noodles w/ Prawns Recipe 泰式冬粉虾
https://www.youtube.com/watch?v=F1oPAXfXuLI&t=40s
Secret Revealed! Super Crispy Chinese Prawn Fritters 炸虾球 Crispy Prawn (Shrimp) Ball Recipe
https://www.youtube.com/watch?v=lKyP-3RClt8&t=94s
How to cook Hong Kong Crispy Garlic Shrimp - Typhoon Shelter Fried Prawns 避风塘炒虾 Chinese Prawn Recipe
https://www.youtube.com/watch?v=Q7FOlkXFuBg&t=80s
Disclaimer:
Spice N' Pans is not related to these products and cannot guarantee the quality of the products in the links provided. Links are provided here for your convenience. We can only stand by the brands of the products we used in the video and we highly recommend you to buy them. Even then, preference can be subjective. Please buy at your own risk. Some of the links provided here may be affiliated. These links are important as they help to fund this channel so that we can continue to give you more recipes. Cheers!

bring convenience 在 Microwave - Pinterest 的美食出口停車場
Oct 29, 2015 - Like Dalda brings #TrueConvenience in cooking, how do you bring convenience in your daily life? Share it with us in our post application and ... ... <看更多>
bring convenience 在 没有照片描述。 - Facebook - 登录或注册 的美食出口停車場
Bring convenience and fun to your daily commute in the Chevrolet Impala. http://bit.ly/2z8EFNB. ... <看更多>