From 00cd66b16956a75a1c8dfb1f267b9a26603c09c7 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Mon, 20 Sep 2021 10:08:54 +0200 Subject: ics, ucs: generate event IDs with a random number Until now, ucs generated unique IDs with the datetime and the number of an event, starting by 0. Unfortunately, if two calendars were generated at the same second, they could have collisions. To avoid that, the ICS generator now uses a base ID generated randomly, which should be enough to avoid collisions. The RNG is self-initialised in the main function. Signed-off-by: Alban Gruin --- src/ics.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/ics.ml') diff --git a/src/ics.ml b/src/ics.ml index 732cbd5..4de1897 100644 --- a/src/ics.ml +++ b/src/ics.ml @@ -19,6 +19,8 @@ open CalendarLib module StringSet = Set.Make (String) +let rng_bound = int_of_float (2. ** 30.) - 1 + let to_date = Printer.Calendar.sprint "%Y%m%dT%H%M%S" let current_date () = to_date @@ Calendar.now () @@ -101,5 +103,5 @@ let to_string tz events = VERSION:2.0\r\n\ PRODID:-//ucs//\r\n" ^ vtimezone - ^ gen_events 0 "" events + ^ gen_events (Random.int rng_bound) "" events ^ "END:VCALENDAR\r\n" -- cgit v1.2.1