This commit is contained in:
Jeffrey Paul 2019-03-23 02:57:58 -07:00
parent fddea37fec
commit 830e6b66bf
3 changed files with 24 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/sneak/gopoker/pokercore"
"io"
"net/http"
"net/rpc"

10
misc/generateTestSuite.go Normal file
View File

@ -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)
}

View File

@ -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()