From 830e6b66bfa7591f055bbdbece74e22d0d7a3f52 Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Sat, 23 Mar 2019 02:57:58 -0700 Subject: [PATCH] testing --- main.go | 1 + misc/generateTestSuite.go | 10 ++++++++++ pokercore/pokercore.go | 26 +++++++++++++------------- 3 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 misc/generateTestSuite.go diff --git a/main.go b/main.go index adbe6c1..af490fa 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" log "github.com/sirupsen/logrus" + "github.com/sneak/gopoker/pokercore" "io" "net/http" "net/rpc" diff --git a/misc/generateTestSuite.go b/misc/generateTestSuite.go new file mode 100644 index 0000000..5ea67de --- /dev/null +++ b/misc/generateTestSuite.go @@ -0,0 +1,10 @@ +package main + +import "fmt" +import "github.com/sneak/gopoker/pokercore" + +func main() { + myDeck := pokercore.NewDeck() + myDeck.ShuffleRandomly() + fmt.Println("%s", myDeck.Cards) +} diff --git a/pokercore/pokercore.go b/pokercore/pokercore.go index 302cb3e..d85274e 100644 --- a/pokercore/pokercore.go +++ b/pokercore/pokercore.go @@ -54,14 +54,6 @@ func NewRandom() *rand.Rand { var rnd *rand.Rand - seed := int64(42) - - if trueRandom { - rnd = rand.New(rand.NewSource(int64(cryptoUint64()))) - } else { - rnd = rand.New(rand.NewSource(seed)) - } - return rnd } @@ -96,7 +88,6 @@ func NewDeck() *Deck { self.Cards = make([]*Card, 52) - // Loop over each type and suit appending to the deck tot := 0 for i := 0; i < len(ranks); i++ { for n := 0; n < len(suits); n++ { @@ -111,8 +102,15 @@ func NewDeck() *Deck { return self } -func (self *Deck) Shuffle() { - r := NewRandom() +func (self *Deck) ShuffleRandomly() { + rnd := rand.New(rand.NewSource(int64(cryptoUint64()))) + //FIXME(sneak) not sure if this is constant time or not + rnd.Shuffle(len(self.Cards), func(i, j int) { self.Cards[i], self.Cards[j] = self.Cards[j], self.Cards[i] }) +} + +func (self *Deck) ShuffleDeterministic(int64 seed) { + r := rand.New(rand.NewSource(seed)) + //FIXME(sneak) not sure if this is constant time or not r.Shuffle(len(self.Cards), func(i, j int) { self.Cards[i], self.Cards[j] = self.Cards[j], self.Cards[i] }) } @@ -139,9 +137,11 @@ func (s Cards) String() (output string) { return output } -func main2() { - +func generate() { log.SetLevel(log.DebugLevel) +} + +func proto() { myDeck := NewDeck() myDeck.Shuffle()