/
shuffle.go
42 lines (37 loc) · 876 Bytes
/
shuffle.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package passgen
func shuffle(s *State, in []rune) ([]rune, error) {
r := NewRandSource()
r.Shuffle(len(in), func(i int, j int) {
in[i], in[j] = in[j], in[i]
})
return in, nil
}
type shuffleGenerator struct {
argPatternEntropy *float64
argPattern []rune
}
func (g *shuffleGenerator) Generate(s *State) error {
argState := NewState(s.SharedState, g.argPattern)
err := baseFunctionCallGenerator(
s,
argState,
shuffle,
)
if err != nil {
return err
}
g.argPatternEntropy = &s.patternEntropy
return nil
}
func (g *shuffleGenerator) Entropy(s *State) (float64, error) {
// FIXME: how to calculate entropy?
if g.argPatternEntropy != nil {
return *g.argPatternEntropy, nil
}
return 0, s.errorUnknown(s_entropy_not_calc)
}
func newShuffleGenerator(arg []rune) (*shuffleGenerator, error) {
return &shuffleGenerator{
argPattern: arg,
}, nil
}