Current section

Files

Jump to
soulless lib soulless util.ex
Raw

lib/soulless/util.ex

defmodule Soulless.Util do
def generate_uuid_v4() do
16
|> :crypto.strong_rand_bytes()
|> format_uuid()
end
def format_uuid(bytes) do
hex = Base.encode16(bytes, case: :lower)
"#{String.slice(hex, 0, 8)}-#{String.slice(hex, 8, 4)}-#{String.slice(hex, 12, 4)}-#{String.slice(hex, 16, 4)}-#{String.slice(hex, 20, 12)}"
end
def random_positive_integer(bytes \\ 7) do
bytes
|> :rand.bytes()
|> :binary.decode_unsigned()
end
end