Computer
Who Wins Nobel Prizes?
Read more of this story at Slashdot.
Quitting Your Job Won't Help You Get Paid More Money Right Now
Read more of this story at Slashdot.
Signal President Blasts WhatsApp's Privacy Claims
Read more of this story at Slashdot.
Streaming Services Are Facing Identity Crisis, Research Shows
Read more of this story at Slashdot.
London Bans Most E-Bikes on Public Transport Over Fire Risk
Read more of this story at Slashdot.
Apple Barred From Google Antitrust Trial, $20 Billion Search Deal at Risk
Read more of this story at Slashdot.
Chicago-Sized Iceberg Hid Ancient Ecosystem, Scientists Reveal
Read more of this story at Slashdot.
Google Patches Chrome Sandbox Escape Zero-Day Caught By Kaspersky
Read more of this story at Slashdot.
Ethically Sourced 'Spare' Human Bodies Could Revolutionize Medicine
Read more of this story at Slashdot.
Representative Line: Time for Identification
If you need a unique ID, UUIDs provide a variety of options. It's worth noting that variants 1, 2, and 7 all incorporate a timestamp into the UUID. In the case of variant 7, this has the benefit of making the UUID sortable, which can be convenient in many cases (v1/v2 incorporate a MAC address which means that they're sortable if generated with the same NIC).
I bring this up because Dave inherited some code written by a "guru". Said guru was working before UUIDv7 was a standard, but also didn't have any problems that required sortable UUIDs, and thus had no real reason to use timestamp based UUIDs. They just needed some random identifier and, despite using C#, didn't use the UUID functions built in to the framework. No, they instead did this:
string uniqueID = String.Format("{0:d9}", (DateTime.UtcNow.Ticks / 10) % 1000000000);A Tick is 100 nanoseconds. We divide that by ten, mod by a billion, and then call that our unique identifier.
This is, as you might guess, not unique. First there's the possibility of timestamp collisions: generating two of these too close together in time would collide. Second, the math is just complete nonsense. We divide Ticks by ten (converting hundreds of nanoseconds into thousands of nanoseconds), then we mod by a billion. So every thousand seconds we loop and have a risk of collision again?
Maybe, maybe, these are short-lived IDs and a thousand seconds is plenty of time. But even if that's true, none of this is a good way to do that.
I suppose the saving grace is they use UtcNow and not Now, thus avoiding situations where collisions also happen because of time zones?
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!Open Source Devs Say AI Crawlers Dominate Traffic, Forcing Blocks On Entire Countries
Read more of this story at Slashdot.
GameStop To Invest Corporate Cash In Bitcoin, Following In Footsteps of MicroStrategy
Read more of this story at Slashdot.
Microsoft's Many Outlooks Are Confusing Users
Read more of this story at Slashdot.
DeepSeek-V3 Now Runs At 20 Tokens Per Second On Mac Studio
Read more of this story at Slashdot.
Lisa Su Says Radeon RX 9000 Series Is AMD's Most Successful GPU Launch Ever
Read more of this story at Slashdot.
Trump's Crypto Venture Introduces a Stabelcoin
Read more of this story at Slashdot.
Nearly Half of Canadians Have Cut Cable Entirely
Read more of this story at Slashdot.
After DDOS Attacks, Blizzard Rolls Back Hardcore WoW Deaths For the First Time
Read more of this story at Slashdot.
Google Unveils Gemini 2.5 Pro, Its Latest AI Reasoning Model With Significant Benchmark Gains
Read more of this story at Slashdot.
'I Won't Connect My Dishwasher To Your Stupid Cloud'
Read more of this story at Slashdot.