Skip to content

Commit

Permalink
Pseudo-random numbers: fix cross-platform consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Mar 20, 2024
1 parent c8f531d commit c5102c3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions minidebug_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,17 @@ module PrintBox (Log_to : Shared_config) = struct
else B.empty )

let pseudo_random_color =
let open Int32 in
let rand = ref (1l : int32) in
fun () ->
let ( + ) = Int32.add in
let ( mod ) = Int32.rem in
(rand := Int32.(logxor !rand (shift_left !rand 13)));
let r = 128 + 64 + (Int32.to_int !rand mod 50) in
let r = to_int (128l + 64l + (!rand mod 50l)) in
(rand := Int32.(logxor !rand (shift_right_logical !rand 17)));
let g = 128 + 64 + (Int32.to_int !rand mod 50) in
let g = to_int (128l + 64l + (!rand mod 50l)) in
(rand := Int32.(logxor !rand (shift_left !rand 5)));
let b = 128 + 64 + (Int32.to_int !rand mod 50) in
let b = to_int (128l + 64l + (!rand mod 50l)) in
Printf.sprintf "%x%x%x" r g b

let stack_to_flame ~elapsed_on_close header { body; elapsed; _ } =
Expand Down

0 comments on commit c5102c3

Please sign in to comment.