Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»Representative Line: Time for Identification

    Representative Line: Time for Identification

    March 26, 2025

    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!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHow Otter.ai’s new AI agents can play key roles in your live meetings, and more
    Next Article IT Leader’s Guide to Virtualization

    Related Posts

    News & Updates

    Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

    May 16, 2025
    News & Updates

    Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

    May 16, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Microsoft ‘lies’ about how to uninstall Edge then seemingly removes page from the web

    News & Updates

    Butler – companion for Home Assistant

    Linux

    Microsoft co-founder Paul Allen’s tech museum shut down with vintage computing collection slated for auction

    Development

    Critical SQL Injection Vulnerability in Apache Traffic Control Rated 9.9 CVSS — Patch Now

    Development

    Highlights

    One of the best vlogging cameras I’ve tested is a Canon shaped like a flip phone

    August 3, 2024

    The Canon Powershot V10 is a unique camera for vloggers and content creators who value…

    Bisheng: An Open-Source LLM DevOps Platform Revolutionizing LLM Application Development

    May 20, 2024

    Pay by Link: Revolutionizing Secure Payments for Businesses and Customers

    July 27, 2024

    pumpfun trading bots

    May 5, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.