mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-07 18:37:56 -05:00
fix rand_bytes: init at least the local domain's Rand state
This commit is contained in:
parent
689b932c63
commit
5aec2c99b8
1 changed files with 9 additions and 0 deletions
|
|
@ -1,4 +1,12 @@
|
|||
let initialized_ = Atomic.make false
|
||||
|
||||
let[@inline never] actually_init () = Random.self_init ()
|
||||
|
||||
let[@inline] maybe_init () =
|
||||
if not (Atomic.exchange initialized_ true) then actually_init ()
|
||||
|
||||
let default_rand_bytes_8 () : bytes =
|
||||
maybe_init ();
|
||||
let b = Bytes.create 8 in
|
||||
for i = 0 to 1 do
|
||||
(* rely on the stdlib's [Random] being thread-or-domain safe *)
|
||||
|
|
@ -14,6 +22,7 @@ let default_rand_bytes_8 () : bytes =
|
|||
b
|
||||
|
||||
let default_rand_bytes_16 () : bytes =
|
||||
maybe_init ();
|
||||
let b = Bytes.create 16 in
|
||||
for i = 0 to 4 do
|
||||
(* rely on the stdlib's [Random] being thread-or-domain safe *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue