UUIDRandom creates a numeric universally unique identifier suitable for use as a primary key in FileMaker number fields. The UUID uses random digits instead of a timestamp and node address. This may be required in some situations to preserve the anonymity of the device that generated the UUID.

UUIDRandom encodes the creation timestamp and several random digits as a single delimited integer. For most purposes, FileMaker will ignore the hyphen "-" in number fields; they are only readability aids.

This function generates UUIDs that are meaningfully sortable. UUIDs will first sort by version (non-random, then random), then by creation timestamp.

This function creates a (decimal) numeric UUID, which has performance advantages for file size and find speed in FileMaker. This can be converted to a more conventional text string UUID with the UUIDGetAsRFC4122( uuid ) function, which converts the integer into the conventional hexadecimal representation of an RFC 4122 UUID.

The creation timestamp can be extracted with UUIDGetTimestamp( uuid ).

Examples

Sample input

UUID.Random

Sample output

4-2-077214057917-1451912-12759-108485853052928

Function code

/**
* ======================================
* UUIDRandom
* https://github.com/jbante/FileMaker-Techniques/blob/master/CustomFunctions/UUID/UUIDRandom.fmfn
*
* PURPOSE:
* Creates a numeric universally unique identifier suitable for use as a
* primary key in FileMaker number fields. The UUID is composed almost
* entirely of random digits. This may be useful in some situations to
* preserve the anonymity of the conditions that generated the UUID. The
* values returned by this and related functions have a one-to-one
* correspondence with UUIDs following the RFC 4122 standard - all values
* in the format generated by this function can be converted to RFC 4122,
* and vice versa.
*
* RETURNS:
* A 41-digit delimited number of the form:
* v-r-nnnnnnnnnnnn-nnnnnnn-nnnnn@nnnnnnnnnnnnnnn
* The sections of the UUID correspond to:
* v: A UUID version (type) number
* r: A variant code reserved by the RFC 4122 standard
* n: Random digits, within certain bounds for compatibility with RFC 4122
*
* PARAMETERS: none
*
* DEPENDENCIES: none
*
* NOTES:
* For most practical purposes, FileMaker will ignore the text delimiters
* in values returned by this function.
*
* These functions generates UUIDs that are meaningfully sortable. Values
* sort by version, then creation order, then node (creation device).
*
* This function creates a (decimal) numeric UUID, which has performance
* advantages for file size and find speed in FileMaker. The value can be
* converted to RFC 4122 canonical form (hexadecimal) with the
* UUIDGetAsRFC4122 function.
*
* HISTORY:
* MODIFIED on 2011-02-02 by Jeremy Bante to use a format with a bijective
* relationship with the RFC 4122 format.
* CREATED on 2010-12-02 by Jeremy Bante <http://scr.im/jbantetsg>.
*
* REFERENCES:
* Key values Best Practice: http://filemakerstandards.org/pages/viewpage.action?pageId=557138
* RFC 4122 standard UUID specification: http://tools.ietf.org/html/rfc4122
* UUID functions: https://github.com/jbante/FileMaker-Techniques/tree/master/CustomFunctions/UUID
* ======================================
*/