uuid. Universally unique identifier

^math:uuid[]
^math:uuid[options[3.4.6]

The method outputs random string of format…
    22C0983C-E26E-4169-BD07-77ECE9405BA5

Note: in some OSes outputs pseudorandom string.

This method is useful in cases when it is hard or insensible to use through-numbering of objects, e.g. while performing distributed computing.

UUID is also known as GUID.

Options hash can be specified:
·$.lower(false/true) - to output the result in lower case, upper case by default.  
·$.solid(false/true) - to exclude the '-' character from the result, do not exclude by default.  

Example

A company's branches accumulate orders and periodically send them to headquarters. To ensure identifier's uniqueness, we use UUID.

# different branches accumulate order's information in tables 'orders' and 'order_details'

# create unique identifier
$order_uuid[^math:uuid[]]

# add record about order

^void:sql{
insert into orders
    (order_uuid, date_ordered, total)
values
    ('
$order_uuid
', '$date_ordered', $total)
}
# cycle adding records on ordered goods should be here
^void:sql{
insert into order_details
    (order_uuid, item_id, price)
values
    ('
$order_uuid
', $item_id$price)
}



# parts of tables 'orders' and 'order_details' are periodically retrieved
# and sent (^mail
:send[…]) to headquarters,
# where these parts of tables are added to common tables 'orders' and 'order_details'
# …WITHOUT any problems with multiple instances of 'order_id'


Note: Parser generates UUID based on random numbers, not on time. Parameters are:
variant = DCE;
version = DCE Security version, with embedded POSIX UIDs.
…that means that not all of the UUID bits are picked up at random. It is to be so, indeed:
xxxxxxxx-xxxx-4xxx-{8,9,A,B}xxx-xxxxxxxxxxxx

Detailed information on UUID is available at:
http://www.opengroup.org/onlinepubs/9629399/apdxa.htm



Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 27.01.2021