📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有17部Youtube影片,追蹤數超過0的網紅CarDebuts,也在其Youtube影片中提到,ส่องสายการผลิตและประกอบ Mercedes-Benz EQA 2021-2022 เมอร์เซเดส เบนซ์ อีคิวเอ รถเอสยูวีไฟฟ้ารุ่นเริ่มต้น และมีขนาดเล็กที่สุดของบริษัท Electric athlet...
「range of function」的推薦目錄:
- 關於range of function 在 Taipei Ethereum Meetup Facebook 的精選貼文
- 關於range of function 在 The MeatMen Facebook 的精選貼文
- 關於range of function 在 KEN.L PHOTOGRAPHY Facebook 的最讚貼文
- 關於range of function 在 CarDebuts Youtube 的最讚貼文
- 關於range of function 在 CarDebuts Youtube 的最佳解答
- 關於range of function 在 TianChad 田七摄影 Youtube 的最佳貼文
range of function 在 The MeatMen Facebook 的精選貼文
Ingredients below ⬇️ Bet you have heard of 三杯鸡 (Taiwanese 3 Cup Chicken) but have you heard of one that improves your cognitive function and memory?
Presenting you this Taiwanese Three Cup Chicken with Kinohimitsu Essence of Chicken. This recipe is not your typical braised chicken - these chicken cubes are seasoned with Kinohimitsu Essence of Chicken giving them a rich and deep flavour.
Now, all you need a warm bowl of rice to doused this decadent, gao gravy all over.
⬇️ Ingredients here ⬇️
3 boneless Chicken thighs, approx.500g (cut into bite sizes)
20g Ginger slice (smashed)
5 cloves Garlic (smashed)
2 tsp Cornstarch
2 tsp Cooking oil
1 tbsp Light soy Sauce
1 tbsp Dark soy sauce
1 tbsp Fish sauce
1 bottle of Kinohimitsu Essence of Chicken
1 tbsp Sesame oil
1 tbsp Sugar
¼ cup Cooking wine
10g Basil leaves
----
Full recipe: https://themeatmen.sg/three-cup-chicken-with-essence-of-chicken
----
Kinohimitsu Singapore Essence of Chicken is made with 180 days old free-range chicken and high pressure double boiled to extract and concentrate the essence from chicken. Free from hormones and antibiotics.
range of function 在 KEN.L PHOTOGRAPHY Facebook 的最讚貼文
In 2017, FUJIFILM launched the first medium format camera - GFX50S, and finally launched GFX50S II today after 4 years waiting. Although the second generation is used along the same 50MP Sensor, it is replaced by the GFX100S body design. The T125 is replaced with a new battery W235, and the power is multiplied; also used the same X-Processor 4 like GFX100S too, so that made the system is integrated; With the new design of GFX100S 5-axis 6 stops IBIS, equipped with specific lenses, the stabilisation can go up to 6.5 stops.
Once I was a user of the GFX50S, I was introduced to the X-Photographer team when GFX series was launched, . The impression of this machine is particularly profound. In the past week of using the prototype GFX50Sii, i have a little experiences would like to share.
The picture quality of this machine is absolutely unquestionable, although there is no 100S BSI Sensor focusing system that fast, but it is clearly improved with the first generation 50S focus system, especially in low light environment. The eye's focus sensitivity is also more than whole GFX50 series, there is no high speed and slow continuous shooting but 3shots pre second, and the picture is as detailed with the GFX50S.
The Dynamic Range of GFX50S II only have 12stops (GFX100S 14stops), RAW file is only 14-bit (GFX100S Up to 16-bit), but it is actually very sufficient for general users. Since 50S II has an IBIS system, the Pixel Shift function is retained, and can merge up to 200MP image, which is suitable for products, landscapes, and architecture photograph.
Due to the previous generation of sensor, the filming system can only reach 1080p 30fps, there is no 4K shooting. If you want to do video with this camera, you should consider it.
The price will be cheaper than GFX50R when it first released, I believe it will become the most attractive "entry" medium format camera in the market!
JPG file editied with Capture One Pro 21
Lighting by Profoto B10 LED with OCF Gel kit
Fujifilm UK & Ireland Fujifilm Global Fujifilm X Series US FUJIFILM Hong Kong Fujifilm X Singapore FUJIFILM Malaysia Fujifilm Philippines Fujifilm Danmark FUJIFILM X WORLD
range of function 在 CarDebuts Youtube 的最讚貼文
ส่องสายการผลิตและประกอบ Mercedes-Benz EQA 2021-2022 เมอร์เซเดส เบนซ์ อีคิวเอ รถเอสยูวีไฟฟ้ารุ่นเริ่มต้น และมีขนาดเล็กที่สุดของบริษัท
Electric athlete in the successful format of the GLA:
EQA is the name of the new entry-level model to the all-electric world of Mercedes-EQ vehicles. The dynamic design of its SUV body is an indicator of the driving enjoyment to be found on board. Offering an excellent compromise between performance, costs and time to market, the EQA is the first all-electric member of the compact car vehicle from Mercedes-Benz. A close relation of the GLA, it delivers all the thrilling characteristics of that vehicle, combined in this case with an efficient electric power train. Prices in Germany start at 47,540.50 euros[1].
Efficient driving pleasure:
The EQA is being launched as the EQA 250 (combined electrical consumption: 15.7 kWh/100 km; combined CO2 emissions: 0 g/km) with 140 kW and a range according to NEDC of 486 kilometres[2][3][4]. Further variants to meet specific customer requirements will follow. These will include on the one hand a series of even more athletic all-wheel-drive models with an additional electric powertrain (eATS) and an output of 200 kW or more, and on the other hand a version with a range of more than 500 kilometres (WLTP)4. Mercedes-EQ sees the key to a bigger range not in ever-larger batteries, but in systematic improvement in the efficiency of all vehicle components.
Automatic anticipatory driving:
Navigation with Electric Intelligence calculates as a matter of course the route that will get you to your destination fastest, taking into account charging times, thus taking the stress out of route planning for the driver. On the basis of continual range simulations, the system makes allowance for any necessary charging stops as well as for numerous other factors, such as the topography and the weather. It is also able to react dynamically to changes, for instance in the traffic situation or personal driving style.
Convenient charging and payment:
With Mercedes me Charge, customers have access to what is currently the world's biggest charging network: this currently comprises more than 450,000 AC and DC charging points across 31 countries. Mercedes me Charge allows customers convenient use of the charging stations of various providers, even when travelling abroad. By registering just once, they can benefit from an integrated payment function with a simple billing process.
Green Charging:
Mercedes me Charge enables customers to charge at more than 175,000 public charging points throughout Europe; Mercedes-Benz ensures a subsequent offset with green power.
range of function 在 CarDebuts Youtube 的最佳解答
เผยโฉมตัวจริง All-New Nissan Note e-Power 2021 นิสสัน โน้ต อีเพาเวอร์ โฉมใหม่ เริ่มขาย 23 ธันวาคมนี้ ในประเทศญี่ปุ่น
ระบบขับเคลื่อน 2WD เครื่องยนต์รหัส HR12DE-EM47
รุ่น F ราคา 2,054,800 เยน
รุ่น S ราคา 2,029,500 เยน
รุ่น X ราคา 2,186,800 เยน
Evolution of e-POWER "e-POWER", which has evolved into the second generation, has renewed its motor and inverter. Compared to the predecessor "Note", the motor has improved torque by 10% and output by 6%, achieving more powerful and comfortable starting acceleration and a powerful feeling of acceleration when overtaking from medium and high speeds. The inverter is 40% smaller and 30% lighter than the first generation, and the efficiency of the engine is also improved, which not only improves acceleration performance but also improves fuel efficiency. In addition, by reducing the frequency of engine operation by controlling the system and improving the sound insulation performance of the car body, we have achieved a class of quietness despite being a compact car. In addition, we have developed the world's first control system that actively generates electricity when it is judged that road noise is large based on the road surface condition, and we are improving the quietness.
Advanced safety technology
in all directions Equipped with advanced safety technology that realizes 360 ° safety support, safety in all directions has been improved. In addition, "ProPilot (with Navilink function)" is installed for the first time * 2 . By adding a function linked with the navigation system to the professional pilot who supports driving operations when driving in the same lane on the highway, it is possible to switch the set speed according to the change in the speed limit and decelerate according to the size of the curve. The system assists the driver to reduce the frequency of operation and realize a safe and comfortable drive.
In addition, Nissan's first 1470MPa class ultra-high-tensile steel (ultra-high-strength steel plate for cold pressing) is used for the body frame to achieve both weight reduction and collision safety at a high level.
Exterior design that goes beyond the conventional wisdom of compact cars
A thin headlamp integrated with the front grille, a new V-motion chrome that connects to it, a character line that connects from the front to the rear with a single line, and a clean view that extends below it The advanced, clean and dynamic design of Nissan's new design language, such as the inflection of the richly sloping surface depending on the angle and the distinctive signature rear combination lamp with the shape of one horizontal character that spreads horizontally, while being compact It also has a striking presence. In addition, the front grille has a pattern inspired by Kumiko, a traditional Japanese craft, and has a "design that blends into the Japanese landscape." The sleek and advanced headlamps use a 4-unit LED projector * 3 . Similarly, the optional 16-inch aluminum wheels have a sharp and sophisticated design inspired by Japanese swords, and are designed to remind you of the driving performance of the "e-POWER." We have prepared a wide range of 13 body colors, including 2 tones of 2 colors, to create a lineup that customers can enjoy and choose according to their tastes. Nissan's new cool tone "Opera Move", which was developed for the advanced and dynamic "Vivid Blue" and the new "Note", is a color that suits sophisticated adults.
Advanced and comfortable interior space The
interior design realizes an advanced and comfortable space that overturns the common sense of compact cars. The instrument panel that expands outward is equipped with a meter integrated with the center display, embodying Nissan's new interior design concept that combines advanced feeling and ease of use suitable for electrification. In addition, the bridge-type center console on which a small electronically controlled shift lever sits is equipped with a large storage space and long reach armrests, so you can enjoy both comfortable driving with an innovative design. In addition, the center console in the front seat is equipped with highly convenient functions such as a wireless charger for smartphones * 3 . The rear seats are equipped with a reclining function, ensuring a class-leading spacious space in both the knee room and headroom. Furthermore, in the luggage compartment, by securing a wide opening and luggage compartment width, it is possible to store luggage without stress. Three types of interior colors and materials are available. The X grade is a combination of a jersey seat with gradation stripes and a synthetic leather armrest. The instrument panel also features carbon-like decorations and a long, horizontally-spreading matte chrome finisher for a clean, modern color coordination.
range of function 在 TianChad 田七摄影 Youtube 的最佳貼文
Here's quick tutorial on how to do night #timelapse or #hyperlapse using Samsung phone. It will capture light trails of car and and anything that emit lights. My Samsung Galaxy S20 Ultra was updated with new camera feature (May 2020 firmware). There's new Close-up macro zoom feature on S20 Ultra. Do S20 and S20 + has this new feature too? Comment down and let me know if your S20 Ultra improved in performance and battery life!
Since we can only use the primary lens for Bight Hyperlapse, a wide lens like Moment 18mm lens is recommended
【10% OFF】 @MOMENT LENS & STOREWIDE with code "FIRSTMOMENT10"
https://moment.8ocm68.net/c/2247428/775341/11129
The Samsung Galaxy S20 Ultra is getting that dedicated Close-Up Zoom function, which is specially-designed to improve the phone’s focus performance at close range.
The image quality of the Night mode has been improved as well. Other enhancements that are exclusive to the Ultra include a more responsive fingerprint reader and better sound quality from the speaker.
Feel free to check out my previous video testing the Galaxy S20 Ultra #100xzoom, video record in #HDR10+ and #8Kfootage. You will see the photos and photography behind the scene live in action.
If you find this video helpful, do feel free to subscribe and thumbs up or share with your friends who might be interested.
Leave a comment/question below so I can help you find out. Thanks for watching! #withGalaxy #galaxys20 #galaxys20ultra #batucaves #kualalumpur #myyourshot #mobilephotography
@withgalaxy @galaxymobilejp @samsungmalaysia @samsungmobileusa
【????+?????+???????? ?? ????????】?
http://bit.ly/TianChadYT
***********************
FOLLOW ME ON:
Website: www.TianChad.com
Facebook: http://www.facebook.com/tianchad
Instagram: http://www.instagram.com/tianchad
Twitter: http://www.twitter.com/tianchad
SUPPORT ME THROUGH:
PATREON - https://www.patreon.com/tianchad