Random generators

void urand_set_seed(ulib_uint seed)

Sets the seed of the random number generator.

Parameters:
  • seed – Seed.

UString const *urand_default_charset(void)

Returns the default character set used by random string generators.

Returns:

Default character set.

ulib_int urand(void)

Returns a random integer.

Returns:

Random integer.

ulib_int urand_range(ulib_int start, ulib_uint len)

Returns a random integer in the specified range.

Parameters:
  • start – Start of the range.

  • len – Length of the range.

Returns:

Random integer.

ulib_float urand_float(void)

Returns a random float between 0.0 and 1.0.

Returns:

Random float.

ulib_float urand_float_range(ulib_float start, ulib_float len)

Returns a random float in the specified range.

Parameters:
  • start – Start of the range.

  • len – Length of the range.

Returns:

Random float.

UString urand_string(ulib_uint len, UString const *charset)

Returns a random string.

Note

The returned object must be destroyed by calling ustring_deinit().

Parameters:
  • len – Length of the string.

  • charset – Character set, or NULL for the default alphanumeric character set.

Returns:

Random string.

void urand_str(ulib_uint len, char *buf, UString const *charset)

Populates the buffer with a random string.

Parameters:
  • len – Length of the random string.

  • buf – Buffer to populate.

  • charset – Character set, or NULL for the default alphanumeric character set.

void urand_shuffle(void *array, size_t element_size, ulib_uint length)

Randomly shuffles the elements of the array.

Parameters:
  • array – Array.

  • element_size – Size of each element of the array.

  • length – Length of the array.