com.fasterxml.uuid.impl
Class RandomBasedGenerator

java.lang.Object
  extended by com.fasterxml.uuid.UUIDGenerator
      extended by com.fasterxml.uuid.NoArgGenerator
          extended by com.fasterxml.uuid.impl.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 Summary
protected  Random _random
          Random number generator that this generator uses.
protected  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.
protected static Random _sharedRandom
          Default shared random number generator, used if no random number generator is explicitly specified for instance
 
Constructor Summary
RandomBasedGenerator(Random rnd)
           
 
Method Summary
 UUID generate()
           
 UUIDType getType()
          Accessor for determining type of UUIDs (variant) that this generator instance will produce.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_sharedRandom

protected static Random _sharedRandom
Default shared random number generator, used if no random number generator is explicitly specified for instance


_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 Detail

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 Detail

getType

public UUIDType getType()
Description copied from class: UUIDGenerator
Accessor for determining type of UUIDs (variant) that this generator instance will produce.

Specified by:
getType in class UUIDGenerator

generate

public UUID generate()
Specified by:
generate in class NoArgGenerator


Copyright © 2011 FasterXML.com. All Rights Reserved.