Git Product home page Git Product logo

Comments (5)

gabrielbalan avatar gabrielbalan commented on August 30, 2024 1

Actually, it is partially dependent on randomness.
I was able to trigger the exception consistently by providing my own (adversarial) Random subclass, whose nextBytes() method writes mostly 0xff values.

When _lastEntropy is set to 0xff ff ff ff ff ff ff ff ff ff, you get the exception if you call generate() 2 times within the same millisecond.
For 0xff ff ff ff ff ff ff ff ff 00, you get the exception if you call generate() 257 times within the same millisecond.

So in general (without the adversarial Random :)), there's a 1/2^80 probability to get the exception from the 2nd call during the same millisecond, and 1/2^72 probability to get the exception during the first 257 calls within the same millisecond.

from java-uuid-generator.

cowtowncoder avatar cowtowncoder commented on August 30, 2024

That would result in generating values "too fast": I forget what is the specific granularity (implementation came as contribution). The challenge is that for same millisecond-based timestamp implementation does use secondary counter, but its capacity is limited -- and I suspect that if you generated UUIDs in a busy loop, a single cpu can overflow it.

So failure would NOT be due to heavy load (quite the opposite actually) but on trying to generate LOTS of UUIDs (for regular time-based ones it's 10 million per second; for epoch maybe less).
I doubt typical applications could reach that rate for normal usage, but if that did happen, yes, waiting for 1 millisecond would be something simple to do. Plain old retry would keep on failing until System.currentTimeMilllis() returns the next new value.

from java-uuid-generator.

cowtowncoder avatar cowtowncoder commented on August 30, 2024

Yes, that is compatible with my recollection of how things work.
The choice of random sequence (or, probability) changes number of "overlapping" uuids that can be generated for given time value.
And yes, with bad luck it could be a very low number.
I don't remember what specification says about choosing entropy values only up to half of max size: that would reduce likelihood of overrun, but also reduce entropy wrt security.

I am open to improvements but do not have enough time to spend on digging deep at this point, due to daytime work.

from java-uuid-generator.

gabrielbalan avatar gabrielbalan commented on August 30, 2024

Thank you, sir. You were very helpful.

from java-uuid-generator.

cowtowncoder avatar cowtowncoder commented on August 30, 2024

Thank you for your help here @gabrielbalan !

from java-uuid-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.