Skip to content

Commit a0b4f56

Browse files
authored
Merge pull request #223 from KristianKarl/krikar/seedCLI
Seed the random generator from offline command line
2 parents a189878 + 1eb864d commit a0b4f56

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

graphwalker-cli/src/main/java/org/graphwalker/cli/CLI.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.graphwalker.cli.util.LoggerUtil;
3939
import org.graphwalker.cli.util.UnsupportedFileFormat;
4040
import org.graphwalker.core.event.EventType;
41+
import org.graphwalker.core.generator.SingletonRandomGenerator;
4142
import org.graphwalker.core.machine.Context;
4243
import org.graphwalker.core.machine.MachineException;
4344
import org.graphwalker.core.machine.SimpleMachine;
@@ -452,11 +453,20 @@ private void runCommandOffline() throws Exception, UnsupportedFileFormat {
452453
System.out.println(Util.getStepAsJSON(machine, offline.verbose, offline.unvisited).toString());
453454
}
454455
});
456+
457+
if (offline.seed != 0) {
458+
SingletonRandomGenerator.setSeed(offline.seed);
459+
}
460+
455461
executor.execute();
456462
} else if (!offline.gw3.isEmpty()) {
457463
//TODO Fix gw3. Should not be there
458464
List<Context> contexts = new JsonContextFactory().create(Paths.get(offline.gw3));
459465

466+
if (offline.seed != 0) {
467+
SingletonRandomGenerator.setSeed(offline.seed);
468+
}
469+
460470
if (offline.blocked) {
461471
org.graphwalker.io.common.Util.filterBlockedElements(contexts);
462472
}

graphwalker-cli/src/main/java/org/graphwalker/cli/commands/Offline.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ public class Offline {
5858
@Parameter(names = {"--blocked",
5959
"-b"}, arity = 1, description = "This option enables or disables the BLOCKED feature. When \"-b true\" GraphWalker will filter out elements in models with the keyword BLOCKED. When \"-b false\" GraphWalker will not filter out any elements in models with the keyword BLOCKED.")
6060
public boolean blocked = true;
61+
62+
@Parameter(names = {"--seed", "-d"}, required = false,
63+
description = "Seed the random generator using the provided number.")
64+
public long seed = 0;
6165
}

0 commit comments

Comments
 (0)