uuid_mod Module

Create a random (version 4) Universally Unique Identifier (UUID)

A UUID looks like "4042E716-2556-4715-90F0-C6518463B4E5" and is a random 128-bit number. This is sufficiently random that we can except zero collisions in any relevant timeframe, and so is useful for uniquely identifing simulations, for example.

If compiled with the preprocessor macro GK_HAS_LIBUUID > 0, then it uses a wrapper around the C libuuid library (which must be linked). Otherwise, uses a fallback random number generator.

This module contains its own implementation of the MT19937 psuedo-random number generator (PRNG) so that it doesn't intefere with the PRNG state used in the rest of the program.



Contents


Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: uuid_len = 36

Length of the UUID character


Functions

private elemental function c_signed_char_to_hex(char) result(hex)

Convert a 1-byte integer into hexadecimal

Arguments

Type IntentOptional Attributes Name
integer(kind=c_signed_char), intent(in) :: char

Return Value character(len=2)

private function format_uuid(uuid_in)

Convert an array of 1-byte integers into UUID format: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

Arguments

Type IntentOptional Attributes Name
integer(kind=c_signed_char), intent(in), dimension(16) :: uuid_in

Return Value character(len=uuid_len)

public function generate_uuid()

Generate a version 4 UUID using either the libuuid library, or our own random number generator wrapper

Arguments

None

Return Value character(len=uuid_len)

private function get_random_seed() result(seed)

Uses a method for getting a nice seed for the PRNG taken from gfortran documentation

Arguments

None

Return Value integer