UUID.Random ( )

Function stats

Average user rating
5.0000
260
288
9999
Support
FileMaker 10.0 +
Date posted
13 December 2010
Last updated
13 May 2011
Version
Recursive function
Yes

Author Info
 Jeremy Bante

10 functions

Average Rating 5.0

author_avatar



 

Function overview

Prototype

UUID.Random  (  )


Parameters

No parameters for this function.


Description

Tags:  Uuid   Primary Key  

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
* ======================================
*/

//v-r-mmm mmm mmm mmmTsss ssss-ccccc@nnnnn nnnnn nnnnn
"4-2-" //version and reserved variant code
& Right ( "000000000000" & Floor ( Random * 165208454460 ) ; 12 ) & "-"
& Right ( Random ; 7 ) & "-"
& Right ( "00000" & Floor ( Random * 16384 ) ; 5 ) & "-"
& Right ( "000000000000000" & Floor ( Random * 281474976710656 ) ; 15 )

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/288

    Prototype: UUID.Random( )
    Function Author: Jeremy Bante (http://www.fmfunctions.com/mid/260)
    Last updated: 13 May 2011
    Version: 2.0

*/
// ===================================

 

 

 

 

 

 

 

Top Tags

Text Parsing  (31)
List  (28)
Date  (26)
Format  (23)
XML  (22)
Sql  (18)
Dev  (18)
Debug  (15)
Text  (13)
Layout  (13)
Interface  (13)
Variables  (12)
Filter  (11)
Design  (10)
Layout Objects  (8)
Array  (7)