This is NOT a cryptographically secure RNG. This should NEVER be used for cryptographic operations.
◆ M_RAND_MAX
#define M_RAND_MAX M_UINT64_MAX |
◆ M_rand_t
◆ M_rand_create()
M_rand_t * M_rand_create |
( |
M_uint64 |
seed | ) |
|
Create a random state for use with random number generation.
- Parameters
-
[in] | seed | The seed state. Using the same seed will allow the sequence to be repeated. If 0 the seed will be a combination of system time, local and heap memory addresses. The data is meant to make choosing a random seed harder but still is not cryptographically secure. This not being a cryptographically secure random number generator we are using random data that is not cryptographically secure for speed. |
- Returns
- Random state.
◆ M_rand_destroy()
Destroy a random state.
- Parameters
-
◆ M_rand()
Generate a random number.
Generates a random number from 0 to M_RAND_MAX.
- Parameters
-
[in,out] | state | The state. Optional, can be NULL, but will incur the overhead of M_rand_create(0); M_rand_destroy(); per iteration if not provided. It is possible, in a tight loop on a very fast system for example, the same number could be generated multiple times if the state is NULL. |
- Returns
- A random number.
◆ M_rand_range()
M_uint64 M_rand_range |
( |
M_rand_t * |
state, |
|
|
M_uint64 |
min, |
|
|
M_uint64 |
max |
|
) |
| |
Generate a random number within a given range.
Range is [min, max). Meaning from min to max-1.
- Parameters
-
[in,out] | state | The state. Optional, can be NULL, but will incur the overhead of M_rand_create(0); M_rand_destroy(); per iteration if not provided. It is possible, in a tight loop on a very fast system for example, the same number could be generated multiple times if the state is NULL. |
[in] | min | The min. |
[in] | max | The max. |
◆ M_rand_max()
M_uint64 M_rand_max |
( |
M_rand_t * |
state, |
|
|
M_uint64 |
max |
|
) |
| |
Generate a random number with a given maximum.
Range is [0, max). Meaning from 0 to max-1.
- Parameters
-
[in,out] | state | The state. Optional, can be NULL, but will incur the overhead of M_rand_create(0); M_rand_destroy(); per iteration if not provided. It is possible, in a tight loop on a very fast system for example, the same number could be generated multiple times if the state is NULL. |
[in] | max | The max. |
◆ M_rand_str()
M_bool M_rand_str |
( |
M_rand_t * |
state, |
|
|
const char * |
charset, |
|
|
char * |
out, |
|
|
size_t |
len |
|
) |
| |
Generate a random string based on the provided character set.
- Parameters
-
[in,out] | state | The state. Optional, can be NULL, but will incur the overhead of M_rand_create(0); M_rand_destroy(); per iteration if not provided. It is possible, in a tight loop on a very fast system for example, the same string could be generated multiple times if the state is NULL. |
[in] | charset | Character set to use to generate the random string. |
[out] | out | Buffer to use to hold the resulting random string. Must be len+1 bytes in length or greater to handle NULL terminator. |
[in] | len | Number of characters to generate. Actual number of bytes written will be 1 larger for the NULL terminator. |
- Returns
- M_FALSE on usage error. M_TRUE on success.
◆ M_rand_duplicate()
Duplicate the state of a random number generator.
If state is NULL this is equivalent to M_rand_create(0).
- Parameters
-
- Returns
- Random state.
- See also
- M_rand_jump
◆ M_rand_jump()
Advance the random number generator to generate non-overlapping sequences.
- Parameters
-
- See also
- M_rand_duplicate