diff --git a/README.md b/README.md index 018c17c..9282785 100644 --- a/README.md +++ b/README.md @@ -91,10 +91,11 @@ // simulating some work go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for i := 0; i < total; i++ { start := time.Now() - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) // since ewma decorator is used, we need to pass time.Since(start) bar.Increment(time.Since(start)) } diff --git a/_examples/barExtender/main.go b/_examples/barExtender/main.go index c3a4688..d397494 100644 --- a/_examples/barExtender/main.go +++ b/_examples/barExtender/main.go @@ -10,10 +10,6 @@ "github.com/vbauerster/mpb/v4" "github.com/vbauerster/mpb/v4/decor" ) - -func init() { - rand.Seed(time.Now().UnixNano()) -} func main() { var wg sync.WaitGroup @@ -46,10 +42,11 @@ // simulating some work go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for i := 0; i < total; i++ { start := time.Now() - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) // since ewma decorator is used, we need to pass time.Since(start) bar.Increment(time.Since(start)) } diff --git a/_examples/cancel/main.go b/_examples/cancel/main.go index 9ab3b6e..1c35038 100644 --- a/_examples/cancel/main.go +++ b/_examples/cancel/main.go @@ -10,10 +10,6 @@ "github.com/vbauerster/mpb/v4" "github.com/vbauerster/mpb/v4/decor" ) - -func init() { - rand.Seed(time.Now().UnixNano()) -} func main() { ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) @@ -40,10 +36,11 @@ go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for !bar.Completed() { start := time.Now() - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) // since ewma decorator is used, we need to pass time.Since(start) bar.Increment(time.Since(start)) } diff --git a/_examples/differentWidth/main.go b/_examples/differentWidth/main.go index 500c722..b4875e5 100644 --- a/_examples/differentWidth/main.go +++ b/_examples/differentWidth/main.go @@ -9,10 +9,6 @@ "github.com/vbauerster/mpb/v4" "github.com/vbauerster/mpb/v4/decor" ) - -func init() { - rand.Seed(time.Now().UnixNano()) -} func main() { var wg sync.WaitGroup @@ -46,10 +42,11 @@ // simulating some work go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for i := 0; i < total; i++ { start := time.Now() - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) // since ewma decorator is used, we need to pass time.Since(start) bar.Increment(time.Since(start)) } diff --git a/_examples/merge/main.go b/_examples/merge/main.go index 1cadc73..02d48c8 100644 --- a/_examples/merge/main.go +++ b/_examples/merge/main.go @@ -9,10 +9,6 @@ "github.com/vbauerster/mpb/v4" "github.com/vbauerster/mpb/v4/decor" ) - -func init() { - rand.Seed(time.Now().UnixNano()) -} func main() { var wg sync.WaitGroup @@ -47,10 +43,11 @@ // simulating some work go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for i := 0; i < total; i++ { start := time.Now() - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) // since ewma decorator is used, we need to pass time.Since(start) bar.Increment(time.Since(start)) } diff --git a/_examples/multiBars/main.go b/_examples/multiBars/main.go index 8337576..b249979 100644 --- a/_examples/multiBars/main.go +++ b/_examples/multiBars/main.go @@ -9,10 +9,6 @@ "github.com/vbauerster/mpb/v4" "github.com/vbauerster/mpb/v4/decor" ) - -func init() { - rand.Seed(time.Now().UnixNano()) -} func main() { var wg sync.WaitGroup @@ -41,10 +37,11 @@ // simulating some work go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for i := 0; i < total; i++ { start := time.Now() - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) // since ewma decorator is used, we need to pass time.Since(start) bar.Increment(time.Since(start)) } diff --git a/_examples/poplog/main.go b/_examples/poplog/main.go index 638ae2d..c8d8d60 100644 --- a/_examples/poplog/main.go +++ b/_examples/poplog/main.go @@ -12,7 +12,6 @@ ) func main() { - rand.Seed(time.Now().UnixNano()) p := mpb.New(mpb.PopCompletedMode()) total, numBars := 100, 2 @@ -32,10 +31,11 @@ ) // simulating some work go func() { + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for i := 0; i < total; i++ { start := time.Now() - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) bar.Increment(time.Since(start)) } }() @@ -45,10 +45,11 @@ wg.Add(1) go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 3000 * time.Millisecond for i := 0; i < 10; i++ { p.Add(0, makeLogBar(fmt.Sprintf("some log: %d", i))).SetTotal(0, true) - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) } }() diff --git a/_examples/quietMode/main.go b/_examples/quietMode/main.go index ae527c5..5297269 100644 --- a/_examples/quietMode/main.go +++ b/_examples/quietMode/main.go @@ -14,7 +14,6 @@ var quietMode bool func init() { - rand.Seed(time.Now().UnixNano()) flag.BoolVar(&quietMode, "q", false, "quiet mode") } @@ -56,10 +55,11 @@ // simulating some work go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for i := 0; i < total; i++ { start := time.Now() - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) // since ewma decorator is used, we need to pass time.Since(start) bar.Increment(time.Since(start)) } diff --git a/_examples/remove/main.go b/_examples/remove/main.go index e78fe40..33cd34a 100644 --- a/_examples/remove/main.go +++ b/_examples/remove/main.go @@ -9,10 +9,6 @@ "github.com/vbauerster/mpb/v4" "github.com/vbauerster/mpb/v4/decor" ) - -func init() { - rand.Seed(time.Now().UnixNano()) -} func main() { var wg sync.WaitGroup @@ -33,6 +29,7 @@ ) go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for i := 0; !b.Completed(); i++ { start := time.Now() @@ -40,7 +37,7 @@ // aborting and removing while bar is running b.Abort(true) } - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) // since ewma decorator is used, we need to pass time.Since(start) b.Increment(time.Since(start)) } diff --git a/_examples/reverseBar/main.go b/_examples/reverseBar/main.go index 9bd513b..8fd1b27 100644 --- a/_examples/reverseBar/main.go +++ b/_examples/reverseBar/main.go @@ -9,10 +9,6 @@ "github.com/vbauerster/mpb/v4" "github.com/vbauerster/mpb/v4/decor" ) - -func init() { - rand.Seed(time.Now().UnixNano()) -} func main() { var wg sync.WaitGroup @@ -44,10 +40,11 @@ // simulating some work go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for i := 0; i < total; i++ { start := time.Now() - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) // since ewma decorator is used, we need to pass time.Since(start) bar.Increment(time.Since(start)) } diff --git a/_examples/singleBar/main.go b/_examples/singleBar/main.go index 029b48b..0f10483 100644 --- a/_examples/singleBar/main.go +++ b/_examples/singleBar/main.go @@ -39,5 +39,4 @@ } // wait for our bar to complete and flush p.Wait() - p.Wait() } diff --git a/_examples/sortBars/go.mod b/_examples/sortBars/go.mod deleted file mode 100644 index 1ef9fcb..0000000 --- a/_examples/sortBars/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/vbauerster/mpb/_examples/sortBars - -go 1.13 - -require github.com/vbauerster/mpb/v4 v4.9.3 diff --git a/_examples/sortBars/main.go b/_examples/sortBars/main.go deleted file mode 100644 index 430f26c..0000000 --- a/_examples/sortBars/main.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "fmt" - "math/rand" - "sync" - "time" - - "github.com/vbauerster/mpb/v4" - "github.com/vbauerster/mpb/v4/decor" -) - -func init() { - rand.Seed(time.Now().UnixNano()) -} - -func main() { - var wg sync.WaitGroup - p := mpb.New(mpb.WithWaitGroup(&wg)) - total := 100 - numBars := 3 - wg.Add(numBars) - - for i := 0; i < numBars; i++ { - name := fmt.Sprintf("Bar#%d:", i) - b := p.AddBar(int64(total), - mpb.BarOptOnCond(mpb.BarWidth(40), func() bool { return i > 0 }), - mpb.PrependDecorators( - decor.Name(name, decor.WCSyncWidth), - decor.CountersNoUnit("%d / %d", decor.WCSyncSpace), - ), - mpb.AppendDecorators( - decor.EwmaETA(decor.ET_STYLE_GO, 60, decor.WC{W: 3}), - ), - ) - go func() { - defer wg.Done() - max := 100 * time.Millisecond - for i := 0; i < total; i++ { - start := time.Now() - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) - if i&1 == 1 { - priority := total - int(b.Current()) - b.SetPriority(priority) - } - // since ewma decorator is used, we need to pass time.Since(start) - b.Increment(time.Since(start)) - } - }() - } - - p.Wait() -} diff --git a/_examples/spinnerBar/main.go b/_examples/spinnerBar/main.go index bb28d17..59f9606 100644 --- a/_examples/spinnerBar/main.go +++ b/_examples/spinnerBar/main.go @@ -9,10 +9,6 @@ "github.com/vbauerster/mpb/v4" "github.com/vbauerster/mpb/v4/decor" ) - -func init() { - rand.Seed(time.Now().UnixNano()) -} func main() { var wg sync.WaitGroup @@ -63,10 +59,11 @@ // simulating some work go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for i := 0; i < total; i++ { start := time.Now() - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) // since ewma decorator is used, we need to pass time.Since(start) bar.Increment(time.Since(start)) } diff --git a/_examples/spinnerDecorator/main.go b/_examples/spinnerDecorator/main.go index 71585e1..ec55f81 100644 --- a/_examples/spinnerDecorator/main.go +++ b/_examples/spinnerDecorator/main.go @@ -9,10 +9,6 @@ "github.com/vbauerster/mpb/v4" "github.com/vbauerster/mpb/v4/decor" ) - -func init() { - rand.Seed(time.Now().UnixNano()) -} func main() { var wg sync.WaitGroup @@ -40,9 +36,10 @@ // simulating some work go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for i := 0; i < total; i++ { - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) bar.Increment() } }() diff --git a/_examples/stress/main.go b/_examples/stress/main.go index 731f94e..2c454a8 100644 --- a/_examples/stress/main.go +++ b/_examples/stress/main.go @@ -13,10 +13,6 @@ const ( totalBars = 32 ) - -func init() { - rand.Seed(time.Now().UnixNano()) -} func main() { var wg sync.WaitGroup @@ -43,9 +39,10 @@ go func() { defer wg.Done() + rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for !bar.Completed() { - time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) bar.Increment() } }() diff --git a/example_test.go b/example_test.go index d82f94e..fd4ec26 100644 --- a/example_test.go +++ b/example_test.go @@ -33,11 +33,10 @@ mpb.AppendDecorators(decor.Percentage()), ) // simulating some work - rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for i := 0; i < total; i++ { start := time.Now() - time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) // since ewma decorator is used, we need to pass time.Since(start) bar.Increment(time.Since(start)) } @@ -49,10 +48,9 @@ p := mpb.New() bar := p.AddBar(100) - rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond for !bar.Completed() { - time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) + time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) bar.Increment() }