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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 15, 2025

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

      May 15, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 15, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 15, 2025

      Intel’s latest Arc graphics driver is ready for DOOM: The Dark Ages, launching for Premium Edition owners on PC today

      May 15, 2025

      NVIDIA’s drivers are causing big problems for DOOM: The Dark Ages, but some fixes are available

      May 15, 2025

      Capcom breaks all-time profit records with 10% income growth after Monster Hunter Wilds sold over 10 million copies in a month

      May 15, 2025

      Microsoft plans to lay off 3% of its workforce, reportedly targeting management cuts as it changes to fit a “dynamic marketplace”

      May 15, 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

      A cross-platform Markdown note-taking application

      May 15, 2025
      Recent

      A cross-platform Markdown note-taking application

      May 15, 2025

      AI Assistant Demo & Tips for Enterprise Projects

      May 15, 2025

      Celebrating Global Accessibility Awareness Day (GAAD)

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

      Intel’s latest Arc graphics driver is ready for DOOM: The Dark Ages, launching for Premium Edition owners on PC today

      May 15, 2025
      Recent

      Intel’s latest Arc graphics driver is ready for DOOM: The Dark Ages, launching for Premium Edition owners on PC today

      May 15, 2025

      NVIDIA’s drivers are causing big problems for DOOM: The Dark Ages, but some fixes are available

      May 15, 2025

      Capcom breaks all-time profit records with 10% income growth after Monster Hunter Wilds sold over 10 million copies in a month

      May 15, 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 

    Hostinger
    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

    Intel’s latest Arc graphics driver is ready for DOOM: The Dark Ages, launching for Premium Edition owners on PC today

    May 15, 2025
    News & Updates

    NVIDIA’s drivers are causing big problems for DOOM: The Dark Ages, but some fixes are available

    May 15, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    CodeSOD: Magical Bytes

    Development

    OutFly – 3D space game in the rings of Jupiter

    Linux

    What is ETL Testing Tutorial Guide

    Development

    Apply a radom pacing in Jmeter without using Timers

    Development

    Highlights

    News & Updates

    CodeSOD: Don’t Date Me

    March 13, 2025

    I remember in some intro-level compsci class learning that credit card numbers were checksummed, and…

    NVIDIA System Monitor is a task manager monitoring your GPU

    May 2, 2025

    Metal Gear Solid Delta: Snake Eater’s release date may have just leaked

    February 6, 2025

    Jagex Launcher for Windows XP: Does It Work for Runescape?

    January 13, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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