• (nodebb)

    There's almost certainly a "Things programmers don't understand about random numbers" compilation out there somewhere. Not gonna bother looking. But Rule 1 ought to be " 'Random' and 'unique' are two unrelated ideas. NEVER mix them up."

  • (nodebb)

    What's interesting is the answer to "if I used a sampler with replacement, how many for that 50% chance of duplicates?"...

    And that answer is "379, duh." Conclusion: it's still probably not enough to be "safe", unless it's for just a small handful of VMs.

  • Missing Semicolon (unregistered)

    Remember, one of the weaknesses of the Enigma Machine was that it never mapped a input character to itself. That hard-coded rule was the chink that let in the codebreakers.

  • Tim R (unregistered)

    what surprises me is that to get to this relatively esoteric function, they must have read past the documentation about plain old random value generation and thought to themselves 'no that's not what I want' !?!?

  • (nodebb)

    Does this application really need the unique IDs to be unpredictable? If not, there's no need for random generation in the first place, just assign sequential numbers.

  • (nodebb) in reply to Barry Margolin

    And to add to what you said, it should probably be handled on the database end (assuming they have one.)

  • (nodebb)

    @Tim R ref

    they must have read past the documentation about plain old random value generation and thought to themselves 'no that's not what I want' !?!?

    My take is this is what happens when everything in your mental world is a string, not a strongly-typed object. They thought of the ID as a string and only as a string. So they needed a stringly generation algorithm. So they cobbled one together from concatenation.

    HTML, JSON, Javascript, etc. Heck, just client/server over http. Everything goes to/from stringly typed data at least once, if not 6 times on the way from one end of the entire app stack to the other. It's the poisoned gift that keeps on destroying what we've known for decades about how to create robust maintainable code that's got heavy safeguards against type misuse.

  • (nodebb) in reply to WTFGuy

    HTML, JSON, Javascript, etc. Heck, just client/server over http. Everything goes to/from stringly typed data at least once, if not 6 times on the way from one end of the entire app stack to the other. It's the poisoned gift that keeps on destroying what we've known for decades

    I second this. I know plenty of people that have decided that since JSON doesn't have a native datetime data type, that it's obviously unnecessary. They argue that date/time data can be represented as strings using ISO 8601 rules. They forget that this addresses part of the problem, but 8601-in-JSON does not provide any mechanism to ensure that the string in the value is valid.

  • (nodebb)

    You just have to wonder, if at some point some manager or user saw the numbers and complained that they didn't "look random enough", and so the developer had to change it to not be able to repeat digits.

  • Hmmmm 🤨 (unregistered)

    They could have gone with return f"{random.randint(0,10**digits):0{digits}}" (and passed in digits as a defaulted parameter).

    I think CS classes try to hammer home the birthday problem, but when you are sitting at your desk scrambling for a unique identifier without setting up some central database service to do so, random often rears its head... and the concept gets reinforced by UUID-v4, but it has 122 random bits and not just 16.6...

    It remains an annoying problem due to having to set up a database, be resilient to restarts and corrupted data, and requiring coordination...

  • (nodebb) in reply to Jaime

    8601-in-JSON does not provide any mechanism to ensure that the string in the value is valid.

    There's no mechanism in JSON to ensure that any value is "valid" beyond being a decimal number, string, boolean, untyped array or object.

  • (nodebb)

    Ah yes, I once worked on a web based application where they generated random session ids and the range was effectively 2^64. It took only a few weeks before the first defect reports of people seeing data belonging to other unrelated people started to come in.

  • (nodebb) in reply to jeremypnet

    There's no mechanism in JSON to ensure that any value is "valid" beyond being a decimal number, string, boolean, untyped array or object.

    Ummm.. that's the point. If a serialization format supports a date datatype, then any attempt to de-serialize a date that doesn't contain date data will error. JSON was originally (and is often still) used schema-less where the de-serializer just gives you whatever is there. Good serialization formats do validation at deserialization time.

Leave a comment on “Plenty of IDs”

Log In or post as a guest

Replying to comment #706127:

« Return to Article