uuid module

Random (version 4) UUIDs. Useful for request IDs, session IDs, and database primary keys when you don't want to round-trip through the DB to mint one.

import "uuid" as uuid;

var id = uuid.v4();
print(id);                      // 550e8400-e29b-41d4-a716-446655440000
print(uuid.is_valid(id));       // true
print(uuid.is_v4(id));          // true

API

FunctionDescription
uuid.v4() → stringA fresh random v4 UUID.
uuid.nil() → stringThe all-zero UUID.
uuid.is_valid(s) → boolTrue for any well-formed UUID string.
uuid.is_v4(s) → boolTrue only for v4 UUIDs (version nibble = 4, variant 8/9/a/b).

See also

  • cryptocrypto.random_bytes(n) if you need raw randomness.
  • random — non-cryptographic RNG for tests and games.