guid()

The guid() function generates and returns a globally unique identifier (GUID) string in UUID version 4 format.

Syntax

guid([PRNG_ALGORITHM])

Parameters

PRNG_ALGORITHM
The name of the algorithm to use for random number generation. If not specified, the default random number generator is used. Specify an algorithm name supported by Java SecureRandom, such as "SHA1PRNG". If the specified algorithm is not supported in the current environment, the default random number generator is used instead.

Description

The guid() function returns a new UUID version 4 string each time it is called. The returned string is in the format xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx, where each character is represented as an uppercase hexadecimal digit.

Error codes

N/A

Usage examples

  1. Generate a default GUID

    json "{}" | eval id = guid()
    | # id: (a different UUID v4 value on each execution)
    
  2. Generate with a specified SecureRandom algorithm

    json "{}" | eval id = guid("SHA1PRNG")
    | # id: (a different UUID v4 value on each execution)
    

Compatibility

The guid() function is available since before Sonar 4.0.