Add unique ids to each Hack build, and handle sigint
[hiphop-php.git] / hphp / hack / src / utils / random_id.ml
blob022af2575afeb4d48a22e30ed7405d735c615a3c
1 (**
2 * Copyright (c) 2015, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the "hack" directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
9 *)
11 let () = Random.self_init ()
13 let base64_alphabet =
14 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
16 let () =
17 assert (String.length base64_alphabet = 64)
19 let short_string () =
20 let r = ref (Random.bits ()) in
21 let cs = ref [] in
22 while !r > 0 do
23 let c = base64_alphabet.[!r mod 64] in
24 cs := String.make 1 c :: !cs;
25 r := !r lsr 6
26 done;
27 String.concat "" !cs