Not so random Randomizer



  • @Jaime said:

    Absolutely.  But, if you are calling something called GenerateGUID and it happens to create a version 4 UUID, you will get back a random number that is suitable as a primary key in a distributed system.  If you call something called tools.Randomizer.getNumber and use it as a primary key, you are an idiot.  GUID are designed to be collision resistant, either through algorithm or keyspace.  Random numbers as a class are not.  Pointing out that there exist a subset of random numbers (version 4 UUIDs) that are collision resistant does little to make that false.  One counter-example is not sufficient.

    I don't think anyone argued that all random numbers are suitable as collision-resistant keys. As I read it, the original argument was whether a random number with a suitably large keyspace could generated collision-resistant keys and it appears it is.



  • @morbiuswilters said:

    I don't think anyone argued that all random numbers are suitable as collision-resistant keys. As I read it, the original argument was whether a random number with a suitably large keyspace could generated collision-resistant keys and it appears it is.

    Precisely.  A 128-bit random number should not have collisions in an application space.  This is not to say that i would ever USE a RNG for a primary key.


  • @morbiuswilters said:

    I don't think anyone argued that all random numbers are suitable as collision-resistant keys. As I read it, the original argument was whether a random number with a suitably large keyspace could generated collision-resistant keys and it appears it is.

    @Original Argument said:

    Back to the OP.... somebody used a random number generator for primary keys and you call the implementation the WTF? Only a bad implementation would ever survive load testing; the concept is TRWTF.

    @First Rebuttal said:

    How much load do you do in your load testing that any randum number generator would fail?  Using a trillion GUIDs gives you about 40 billionths of a percent chance of collision.

    The original argument was whether the concept of using a random number as a PK is sane, which was countered by stating that a subset of random numbers are a perfectly acceptable as keys.  Nobody has disagreed that a suitably large random number would work, but I have repeatedly pointed out that it simply doesn't matter because I never ever said that it was impossible to do, just generally a bad idea.  Repeating the same thing over and over and providing more evidence of the validity of the exception case doesn't address the original point.  A single exception does not invalidate a generality.  Besides, the case presented here isn't a GUID, so the exceptional case isn't even on topic.  The function in the OP returns a value of type "Number" which in ActionScript only has a maximum of 52 bits of precision.  Birthday Paradox math says that the best implementation would have an unacceptable chance of collisions at around a million keys.



  • You also went on to say that@Jaime said:

    I stand by my statement that anything that would be good at avoiding collisions would be a poor implementation of a general purpose random number generator.
    Since you don't need something to avoid collisions in a large number space...



  • @Sutherlands said:

    You also went on to say that@Jaime said:

    I stand by my statement that anything that would be good at avoiding collisions would be a poor implementation of a general purpose random number generator.
    Since you don't need something to avoid collisions in a large number space...

    Apparently our definitions of "general purpose" differ.  Numbers with a lot of bits are unweildy in most languages.  Start with a version 4 UUID and use it to simulate a dice roll; it's much harder than it needs to be.

  • ♿ (Parody)

    @Jaime said:

    @Sutherlands said:
    You also went on to say that
    @Jaime said:
    I stand by my statement that anything that would be good at avoiding collisions would be a poor implementation of a general purpose random number generator.

    Since you don't need something to avoid collisions in a large number space...

    Apparently our definitions of "general purpose" differ.  Numbers with a lot of bits are unweildy in most languages.  Start with a version 4 UUID and use it to simulate a dice roll; it's much harder than it needs to be.

    I guess, although using those UUIDs reminds me of the random number tables in, e.g., old CRC books. It's more difficult to use for a particular purpose, I suppose (like rolling a particular die), but it would probably be better as a general purpose RNG than whatever you'd use for your die rolls, since you ought to be able to adapt it pretty easily to just about anything.


Log in to reply