Documentation › Modules › Util.em

File: Util.em

Utility functions

Last modified: 08/16/2020

File Constants

const UUID_NIL := "00000000-0000-0000-0000-000000000000";
const UUID_MAX := "ffffffff-ffff-ffff-ffff-ffffffffffff";

RandomDiceRoll(dice_string, allow_negatives := 0 )#

Parameters

dice_string String
allow_negatives Integer

Explanation

Returns a random number according to the passed die roll string. This is standard NdS+X format. N=number of dies to roll, S=number of sides per die, X=integer to add(or subtract) after roll.
If
allow_negatives
is
1
, a negative dice roll will be returned as-is, and will not be capped at
0
.
Here's some acceptable examples:
4
d4
d6+6
d6-2
2d12
2d8+12
2d8-4

Return values

Valkyrie's pedantic wording: "returns an integer greater or equal to N+X and not more than N*S+X"

RandomFloat( below_this_float )#

Parameters

below_this_float Real

Explanation

Returns a random real below the passed parameter and greater or equal to zero.

Return values

Real R such that 0 less or equal to R less than below_this_number

Errors

  • "RandomFloat() expects a Real parameter"

RandomInt( below_this_number )#

Parameters

below_this_number Integer

Explanation

Returns a random integer below the passed parameter and greater or equal to zero.

Return values

Integer R such that 0 less or equal to R less than below_this_number

Errors

  • "RandomInt() expects a positive integer"

RandomIntMinMax(minValue, maxValue )#

Parameters

minValue Integer
maxValue Integer

Explanation

Returns a random integer between the Min and Max integers passed. Accepts negative Integers and if parameters in wrong order swaps them.

Return values

Integer Randomly between Min and Max parameters

Errors

  • "RandomIntMinMax() expects an integer"

RandomUUID( version := 4 )#

Explanation

Returns a UUID according to RFC 9562. Supported versions are 4 (random) and 7 (timestamp + random)

Return values

String

Errors

  • "Invalid parameter type"
  • "Invalid version"

StrFormatTime( format_string, time_stamp:=0 )#

Parameters

format_string String
time_stamp Integer

Explanation

Takes in the StrFTime() specifiers for the format string.
If time_stamp is 0, it will use POLCore().systime.
For format_string information, please go to http://www.cppreference.com/stddate/strftime.html

Return values

String

Errors

  • "No time string passed."