Class RandomBasedGenerator


public class RandomBasedGenerator extends NoArgGenerator
Implementation of UUID generator that uses generation method 4.

Note on random number generation when using SecureRandom for random number generation: the first time SecureRandom object is used, there is noticeable delay between calling the method and getting the reply. This is because SecureRandom has to initialize itself to reasonably random state. Thus, if you want to lessen delay, it may be be a good idea to either get the first random UUID asynchronously from a separate thread, or to use the other generateRandomBasedUUID passing a previously initialized SecureRandom instance.

Since:
3.0
  • Field Details

    • _random

      protected final Random _random
      Random number generator that this generator uses.
    • _secureRandom

      protected final boolean _secureRandom
      Looks like SecureRandom implementation is more efficient using single call access (compared to basic Random), so let's use that knowledge to our benefit.
  • Constructor Details

    • RandomBasedGenerator

      public RandomBasedGenerator(Random rnd)
      Parameters:
      rnd - Random number generator to use for generating UUIDs; if null, shared default generator is used. Note that it is strongly recommend to use a good (pseudo) random number generator; for example, JDK's SecureRandom.
  • Method Details