public class CodeGenerator extends Object
MappedStringEncoder.
Codes are first generated as random numbers that are uniformly distributed across
the possible number range. The numbers are subsequently encoded to strings using the encoder.
Use forCodeLength(int) to create a code generator with a default MappedStringEncoder.
The length of the code as well as the number of codes generated will determine the statistical
probability of guessing a code.
Note that there is no uniqueness of codes between calls to the generator.forCodeLength(int)| Constructor and Description |
|---|
CodeGenerator(MappedStringEncoder encoder) |
| Modifier and Type | Method and Description |
|---|---|
static CodeGenerator |
forCodeLength(int length)
Create a CodeGenerator that generates random codes with a specified length.
|
List<String> |
generate(int numberOfCodes)
Generates a number of random codes that are all the same - full - length.
|
List<String> |
generate(int numberOfCodes,
boolean padToLength)
Generates a number of random codes.
|
public CodeGenerator(MappedStringEncoder encoder)
public List<String> generate(int numberOfCodes)
numberOfCodes - Number of codes to generate.IllegalArgumentException - if the number of codes is too large for the configured encoder.public List<String> generate(int numberOfCodes, boolean padToLength)
numberOfCodes - Number of codes to generate.padToLength - True if codes should all be the same - full -length.IllegalArgumentException - if the number of codes is too large for the configured encoder.public static CodeGenerator forCodeLength(int length)
length - Length of a code.Copyright © 2017. All rights reserved.