Skip to content

Commit

Permalink
Use Int32 for pseudo-random numbers for cross-platform consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Mar 20, 2024
1 parent c52fc45 commit af7cd84
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
14 changes: 7 additions & 7 deletions minidebug_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,14 @@ module PrintBox (Log_to : Shared_config) = struct
else B.empty )

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

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

0 comments on commit af7cd84

Please sign in to comment.