From cb8e8cae5295dec4e3d2ce897f73c0ddfb49a875 Mon Sep 17 00:00:00 2001 From: gedi Date: Mon, 26 Nov 2018 09:48:18 +0200 Subject: [PATCH] closes #146 --- flags.go | 7 +++---- run.go | 8 +++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/flags.go b/flags.go index 0eb2347..d31dee5 100644 --- a/flags.go +++ b/flags.go @@ -196,14 +196,13 @@ type randomSeed struct { // Choose randomly assigns a convenient pseudo-random seed value. // The resulting seed will be between `1-99999` for later ease of specification. -func (rs *randomSeed) choose() { - r := rand.New(rand.NewSource(time.Now().UTC().UnixNano())) - *rs.ref = r.Int63n(99998) + 1 +func makeRandomSeed() int64 { + return rand.New(rand.NewSource(time.Now().UTC().UnixNano())).Int63n(99998) + 1 } func (rs *randomSeed) Set(s string) error { if s == "true" { - rs.choose() + *rs.ref = makeRandomSeed() return nil } diff --git a/run.go b/run.go index fcd70f7..84fbf34 100644 --- a/run.go +++ b/run.go @@ -145,11 +145,17 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt return exitOptionError } + // user may have specified -1 option to create random seed + randomize := opt.Randomize + if randomize == -1 { + randomize = makeRandomSeed() + } + r := runner{ fmt: formatter(suite, output), initializer: contextInitializer, features: features, - randomSeed: opt.Randomize, + randomSeed: randomize, stopOnFailure: opt.StopOnFailure, strict: opt.Strict, }