source: code/trunk/lib/id.ml@ 77

Last change on this file since 77 was 62, checked in by yakumo.izuru, 13 months ago

Remove the old UUID code, update the mailing list address, and use 'favicon.ico'

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 628 bytes
RevLine 
[3]1let random_state = Random.State.make_self_init
2
3type t = string
[39]4let compare = String.compare
[3]5let nil = ""
6
7let short ?(len) id =
8 let id_len = String.length id in
9 let l = match len with Some l -> l | None -> if id_len = 36 then 8 else 6 in
10 String.sub id 0 (min l id_len)
11
12let generate ?(len=6) ?(seed=random_state ()) () =
13 let b32 i = char_of_int @@
14 if i < 10 then i+48 else
15 if i < 18 then i+87 else
16 if i < 20 then i+88 else
17 if i < 22 then i+89 else
18 if i < 27 then i+90 else
19 if i < 32 then i+91 else
20 (invalid_arg ("id.char" ^ string_of_int i)) in
21 let c _ = b32 (Random.State.int seed 31) in
22 String.init len c
Note: See TracBrowser for help on using the repository browser.