public interface VertxContextPRNG
When applicable, use of VertxContextPRNG rather than create new PRNG objects is helpful to keep the system entropy usage to the minimum avoiding potential blocking across the application.
The use of VertxContextPRNG is particularly appropriate when multiple handlers use random numbers.
Modifier and Type | Method and Description |
---|---|
void |
close()
stop seeding the PRNG
|
static VertxContextPRNG |
current()
Get or create a secure non blocking random number generator using the current vert.x context.
|
static VertxContextPRNG |
current(Context context)
Get or create a secure non blocking random number generator using the provided vert.x context.
|
static VertxContextPRNG |
current(Vertx vertx)
Get or create a secure non blocking random number generator using the current vert.x instance.
|
boolean |
nextBoolean()
Returns a secure random boolean
|
void |
nextBytes(byte[] bytes)
Fills the given byte array with random bytes.
|
double |
nextDouble()
Returns a secure random double value.
|
float |
nextFloat()
Returns a secure random float value.
|
double |
nextGaussian()
Returns a secure random double value.
|
int |
nextInt()
Returns a secure random int
|
int |
nextInt(int bound)
Returns a secure random int, between 0 (inclusive) and the specified bound (exclusive).
|
long |
nextLong()
Returns a secure random long
|
String |
nextString(int length)
Returns a Base64 url encoded String of random data with the given length.
|
static VertxContextPRNG current()
IllegalStateException
is thrown.
Note, if a context isn't allowed to be used, for example, exceptions are thrown on getting and putting data,
the VertxContextPRNG falls back to instantiate a new instance of the PRNG per call.IllegalStateException
- when there is no Context
instance available.static VertxContextPRNG current(Context context)
context
- a Vert.x context.IllegalStateException
- when there is no Vertx
instance available.static VertxContextPRNG current(Vertx vertx)
vertx
- a Vert.x instance.void close()
void nextBytes(byte[] bytes)
bytes
- a byte array.String nextString(int length)
length
- the desired string length before Base64 encoding.int nextInt()
int nextInt(int bound)
bound
- the upper bound (exclusive), which must be positive.boolean nextBoolean()
long nextLong()
float nextFloat()
double nextDouble()
double nextGaussian()
Copyright © 2024 Eclipse. All rights reserved.