Changeset 3 in code for trunk/lib/id.ml
- Timestamp:
- Apr 15, 2022, 1:17:01 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/id.ml
r2 r3 1 let random_state = Random.State.make_self_init () 2 type t = Uuidm.t 3 let compare = Uuidm.compare 4 let to_string = Uuidm.to_string 5 let of_string = Uuidm.of_string 6 let to_bytes = Uuidm.to_bytes 7 let of_bytes = Uuidm.of_bytes 8 let generate ?(random_state=random_state) = Uuidm.v4_gen random_state 9 let nil = Uuidm.nil 1 let random_state = Random.State.make_self_init 2 3 (*module UUID = struct*) 4 (*type t = Uuidm.t*) 5 (*let compare = Uuidm.compare*) 6 (*let to_string = Uuidm.to_string*) 7 (*let of_string = Uuidm.of_string*) 8 (*let to_bytes = Uuidm.to_bytes*) 9 (*let of_bytes = Uuidm.of_bytes*) 10 (*let generate ?(random_state=random_state ()) = Uuidm.v4_gen random_state*) 11 (*let nil = Uuidm.nil*) 12 (*end*) 13 14 type t = string 15 let compare = String.compare 16 let nil = "" 17 18 let short ?(len) id = 19 let id_len = String.length id in 20 let l = match len with Some l -> l | None -> if id_len = 36 then 8 else 6 in 21 String.sub id 0 (min l id_len) 22 23 let generate ?(len=6) ?(seed=random_state ()) () = 24 let b32 i = char_of_int @@ 25 if i < 10 then i+48 else 26 if i < 18 then i+87 else 27 if i < 20 then i+88 else 28 if i < 22 then i+89 else 29 if i < 27 then i+90 else 30 if i < 32 then i+91 else 31 (invalid_arg ("id.char" ^ string_of_int i)) in 32 let c _ = b32 (Random.State.int seed 31) in 33 String.init len c
Note:
See TracChangeset
for help on using the changeset viewer.