Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Add a seed for better randomness
Browse files Browse the repository at this point in the history
Without the seed the rand.Intn will always start from the same place and
return the same application name

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
  • Loading branch information
rumpl committed Nov 13, 2019
1 parent 80c0233 commit 642f8bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/cnab-run/main.go
Expand Up @@ -3,7 +3,9 @@ package main
import (
"errors"
"fmt"
"math/rand"
"os"
"time"

"github.com/docker/app/internal"
)
Expand Down Expand Up @@ -38,6 +40,7 @@ func getCnabAction() (cnabAction, string, error) {
}

func main() {
rand.Seed(time.Now().UnixNano())
action, actionName, err := getCnabAction()
if err != nil {
fmt.Fprintf(os.Stderr, "Error while parsing CNAB operation: %s", err)
Expand Down
4 changes: 4 additions & 0 deletions cmd/docker-app/main.go
@@ -1,6 +1,9 @@
package main

import (
"math/rand"
"time"

"github.com/docker/app/internal"
app "github.com/docker/app/internal/commands"
"github.com/docker/cli/cli-plugins/manager"
Expand All @@ -10,6 +13,7 @@ import (
)

func main() {
rand.Seed(time.Now().UnixNano())
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
cmd := app.NewRootCmd("app", dockerCli)
originalPreRun := cmd.PersistentPreRunE
Expand Down

0 comments on commit 642f8bc

Please sign in to comment.