polserver/docs/docs.polserver.com/pol100/utilem.xml
Kevin Eady c029ca4283
Add module function util::RandomUUID() (#803)
* implementation

* tests

* docs

* add uuid_nil, uuid_max

* add support for v4 or v7 uuid generation
2025-08-16 13:39:34 +02:00

75 lines
3.4 KiB
XML

<?xml version='1.0' encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="escript.xslt" ?>
<!DOCTYPE ESCRIPT SYSTEM "escript.dtd">
<ESCRIPT>
<fileheader fname="Util.em">
<filedesc>Utility functions</filedesc>
<datemodified>08/16/2020</datemodified>
<constant>const UUID_NIL := "00000000-0000-0000-0000-000000000000";</constant>
<constant>const UUID_MAX := "ffffffff-ffff-ffff-ffff-ffffffffffff";</constant>
</fileheader>
<function name="RandomInt">
<prototype>RandomInt(below_this_number)</prototype>
<parameter name="below_this_number" value="Integer" />
<explain>Returns a random integer below the passed parameter and greater or equal to zero.</explain>
<return>Integer R such that 0 less or equal to R less than below_this_number</return>
<error>"RandomInt() expects a positive integer"</error>
</function>
<function name="RandomIntMinMax">
<prototype>RandomIntMinMax(minValue, maxValue)</prototype>
<parameter name="minValue" value="Integer" />
<parameter name="maxValue" value="Integer" />
<explain>Returns a random integer between the Min and Max integers passed. Accepts negative Integers and if parameters in wrong order swaps them.</explain>
<return>Integer Randomly between Min and Max parameters</return>
<error>"RandomIntMinMax() expects an integer"</error>
</function>
<function name="RandomFloat">
<prototype>RandomFloat(below_this_float)</prototype>
<parameter name="below_this_float" value="Real" />
<explain>Returns a random real below the passed parameter and greater or equal to zero.</explain>
<return>Real R such that 0 less or equal to R less than below_this_number</return>
<error>"RandomFloat() expects a Real parameter"</error>
</function>
<function name="RandomDiceRoll">
<prototype>RandomDiceRoll(dice_string, allow_negatives := 0)</prototype>
<parameter name="dice_string" value="String" />
<parameter name="allow_negatives" value="Integer"/>
<explain>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.</explain>
<explain>If <code>allow_negatives</code> is <code>1</code>, a negative dice roll will be returned as-is, and will not be capped at <code>0</code>.</explain>
<explain>Here's some acceptable examples:
<code>
4
d4
d6+6
d6-2
2d12
2d8+12
2d8-4
</code></explain>
<return>Valkyrie's pedantic wording: "returns an integer greater or equal to N+X and not more than N*S+X"</return>
</function>
<function name="RandomUUID">
<prototype>RandomUUID( version := 4 )</prototype>
<explain>Returns a UUID according to RFC 9562. Supported versions are 4 (random) and 7 (timestamp + random)</explain>
<return>String</return>
<error>"Invalid parameter type"</error>
<error>"Invalid version"</error>
</function>
<function name="StrFormatTime">
<prototype>StrFormatTime( format_string, time_stamp:=0 )</prototype>
<parameter name="format_string" value="String" />
<parameter name="time_stamp" value="Integer" />
<explain>Takes in the StrFTime() specifiers for the format string.</explain>
<explain>If time_stamp is 0, it will use POLCore().systime.</explain>
<explain>For format_string information, please go to http://www.cppreference.com/stddate/strftime.html</explain>
<return>String</return>
<error>"No time string passed."</error>
</function>
</ESCRIPT>