Module uuid
Copyright 2012 Rackspace (original), 2013-2024 Thijs Schreijer (modifications)
see http://www.ietf.org/rfc/rfc4122.txt and https://www.ietf.org/rfc/rfc9562.txt
Info:
- License: Apache 2.0, see LICENSE.md.
Functions
set_rng (func[, err]) | Sets the function to be used to generate random bytes. |
v4 () | Creates a new v4 uuid. |
Functions
- set_rng (func[, err])
-
Sets the function to be used to generate random bytes. The signature of
the function should be
func(n)
, wheren
is the number of bytes to generate. The function should return a binary string of random bytes (not hex or otherwise encoded). Upon error it should returnnil + error message
.The second parameter is used to directly pass in errors from the rng functions. See the example.
Parameters:
- func function the function to be used to generate random bytes
- err
string
optional error message to be thrown when
func
is not a function (optional)
Returns:
-
boolean
true
Usage:
-- set the random number generator for /dev/urandom. On Windows this isn't available -- and it returns
nil+error
, which is passed on to set_rng which then -- throws a meaningful error. uuid.set_rng(uuid.rng.urandom()) - v4 ()
-
Creates a new v4 uuid.
Calling on the module table is a shortcut for this function.
Returns:
-
string
a properly formatted uuid string