-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathzipf_test.go
74 lines (70 loc) · 1.42 KB
/
zipf_test.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package ddtxn
import (
"fmt"
"math/rand"
"testing"
"time"
)
func TestGenZipf(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
z := NewZipf(r, 1.000001, 1, uint64(100))
n := 1000
x := make([]uint64, n)
for i := 0; i < n; i++ {
x[i] = z.Uint64()
}
first := 0
second := 0
third := 0
for i := 0; i < len(x); i++ {
if x[i] == uint64(0) {
first++
} else if x[i] == uint64(1) {
second++
} else if x[i] == 2 {
third++
}
}
fmt.Printf("mine 1.000001,: first: %v, second: %v, third: %v\n", first, second, third)
z = NewZipf(r, .9999, 1, uint64(100))
n = 1000
x = make([]uint64, n)
for i := 0; i < n; i++ {
x[i] = z.Uint64()
}
first = 0
second = 0
third = 0
for i := 0; i < len(x); i++ {
if x[i] == uint64(0) {
first++
} else if x[i] == uint64(1) {
second++
} else if x[i] == 2 {
third++
}
}
fmt.Printf("mine .9999: first: %v, second: %v, third: %v\n", first, second, third)
}
func TestGenZipfGo(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
z := rand.NewZipf(r, 1.000001, 1, uint64(100))
n := 1000
x := make([]uint64, n)
for i := 0; i < n; i++ {
x[i] = z.Uint64()
}
first := 0
second := 0
third := 0
for i := 0; i < len(x); i++ {
if x[i] == uint64(0) {
first++
} else if x[i] == uint64(1) {
second++
} else if x[i] == 2 {
third++
}
}
fmt.Printf("go 1.000001: first: %v, second: %v, third: %v\n", first, second, third)
}