Skip to content
Snippets Groups Projects
Commit 242356f3 authored by erwan's avatar erwan
Browse files

Fix: the seed init should be done *before* the process init (otherwise there...

Fix: the seed init should be done *before* the process init (otherwise there is no randomness in the initial configuration!)
parent 8b6dea1f
No related branches found
No related tags found
No related merge requests found
Pipeline #64064 passed
(* Time-stamp: <modified the 02/04/2021 (at 10:59) by Erwan Jahier> *)
(* Time-stamp: <modified the 02/04/2021 (at 15:47) by Erwan Jahier> *)
open Register
......@@ -176,6 +176,7 @@ let (make : bool -> string array -> 'v t) =
flush stdout;
exit 2
in
let seed = seed_get args in
try
let dynlink = if args.output_algos then false else dynlink in
let dot_file = args.topo in
......@@ -273,7 +274,6 @@ let (make : bool -> string array -> 'v t) =
close_out oc;
Printf.eprintf " [sasa] %s has been generated.\n%!" fn;
exit 0);
let seed = seed_get args in
if args.no_data_file then () else (
let oc = if args.rif then stderr else stdout in
if !Register.verbose_level > 0 then Printf.eprintf "==> open rif file...\n%!";
......
(* Time-stamp: <modified the 02/12/2020 (at 11:14) by Erwan Jahier> *)
(* Time-stamp: <modified the 02/04/2021 (at 15:45) by Erwan Jahier> *)
type t = {
......@@ -126,25 +126,26 @@ let reset_the_seed_to_last args =
Printf.eprintf " [sasa] W: cannot recover the seed in %s\n" f;
flush stderr;
false
let rec seed_get args = match args.seed with
let rec seed_get args =
match args.seed with
| Some i -> i
| None ->
(* No seed is set:
- in -replay mode, we first try to read the seed in the seed file
- otherwise, we create a random seed and save if into args, and
into a file for -replay *)
if args.replay_seed && reset_the_seed_to_last args then (seed_get args) else
let seed = Random.self_init (); Random.int 1073741823 in
let seed_file = seed_file_name args in
let oc = open_out seed_file in
Printf.fprintf oc "%d\n%s\n" seed
(Mypervasives.entete "#" SasaVersion.str SasaVersion.sha);
flush oc;
close_out oc;
seed_set args (Some seed);
seed
(* No seed is set:
- in -replay mode, we first try to read the seed in the seed file
- otherwise, we create a random seed and save if into args, and
into a file for -replay *)
if args.replay_seed && reset_the_seed_to_last args then (seed_get args) else (
let seed = Random.self_init (); Random.int 1073741823 in
let seed_file = seed_file_name args in
let oc = open_out seed_file in
Printf.fprintf oc "%d\n%s\n" seed
(Mypervasives.entete "#" SasaVersion.str SasaVersion.sha);
flush oc;
close_out oc;
seed_set args (Some seed);
seed
)
(*******************************************************************************)
(*** User Options Tab **)
......@@ -280,16 +281,16 @@ let unexpected s = (
let parse argv = (
let save_current = !current in
try (
let args = make_args () in
let args = make_args () in
mkoptab argv args;
Arg.parse_argv ~current:current argv args._args (add_other args) (usage_msg argv.(0));
Arg.parse_argv ~current:current argv args._args (add_other args) (usage_msg argv.(0));
(List.iter
(fun f ->
if (String.sub f 0 1 = "-") then
unexpected f
else if not (Sys.file_exists f) then
file_notfound f
else ()
if (String.sub f 0 1 = "-") then
unexpected f
else if not (Sys.file_exists f) then
file_notfound f
else ()
)
args._others);
current := save_current;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment