Last change
on this file since 39 was 39, checked in by fox, 2 years ago |
Read References field; referred by listing; test & tidy documentation
|
File size:
956 bytes
|
Line | |
---|
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
TracBrowser
for help on using the repository browser.