kosuzu/lib/id.ml
fox 1547dc4d27 Read References field; referred by listing; test & tidy documentation
git-svn-id: file:///srv/svn/repo/kosuzu/trunk@39 eb64cd80-c68d-6f47-b6a3-0ada418499da
2022-12-12 22:52:55 +00:00

34 lines
956 B
OCaml

let random_state = Random.State.make_self_init
(*module UUID = struct*)
(*type t = Uuidm.t*)
(*let compare = Uuidm.compare*)
(*let to_string = Uuidm.to_string*)
(*let of_string = Uuidm.of_string*)
(*let to_bytes = Uuidm.to_bytes*)
(*let of_bytes = Uuidm.of_bytes*)
(*let generate ?(random_state=random_state ()) = Uuidm.v4_gen random_state*)
(*let nil = Uuidm.nil*)
(*end*)
type t = string
let compare = String.compare
let nil = ""
let short ?(len) id =
let id_len = String.length id in
let l = match len with Some l -> l | None -> if id_len = 36 then 8 else 6 in
String.sub id 0 (min l id_len)
let generate ?(len=6) ?(seed=random_state ()) () =
let b32 i = char_of_int @@
if i < 10 then i+48 else
if i < 18 then i+87 else
if i < 20 then i+88 else
if i < 22 then i+89 else
if i < 27 then i+90 else
if i < 32 then i+91 else
(invalid_arg ("id.char" ^ string_of_int i)) in
let c _ = b32 (Random.State.int seed 31) in
String.init len c