kosuzu/lib/id.ml
yakumo.izuru 717edc5d79 Remove the old UUID code, update the mailing list address, and use 'favicon.ico'
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>

git-svn-id: file:///srv/svn/repo/kosuzu/trunk@62 eb64cd80-c68d-6f47-b6a3-0ada418499da
2024-04-01 14:38:02 +00:00

23 lines
628 B
OCaml

let random_state = Random.State.make_self_init
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