| 1 |
package tester |
| 2 |
|
| 3 |
import ( |
| 4 |
"math/rand" |
| 5 |
"time" |
| 6 |
) |
| 7 |
|
| 8 |
func prepareStrings(seed int64) (A, B []string) { |
| 9 |
if seed == -1 { |
| 10 |
seed = time.Now().UnixNano() |
| 11 |
} |
| 12 |
rand.Seed(seed) |
| 13 |
|
| 14 |
lines := [4000]string{} |
| 15 |
for i := range lines { |
| 16 |
l := rand.Intn(100) |
| 17 |
p := make([]byte, l) |
| 18 |
rand.Read(p) |
| 19 |
lines[i] = string(p) |
| 20 |
} |
| 21 |
|
| 22 |
A = make([]string, 4000) |
| 23 |
B = make([]string, len(A)) |
| 24 |
for i := range A { |
| 25 |
|
| 26 |
if rand.Intn(100) < 40 { |
| 27 |
A[i] = lines[rand.Intn(50)] |
| 28 |
} else { |
| 29 |
A[i] = lines[rand.Intn(len(lines))] |
| 30 |
} |
| 31 |
if rand.Intn(100) < 40 { |
| 32 |
B[i] = lines[rand.Intn(50)] |
| 33 |
} else { |
| 34 |
B[i] = lines[rand.Intn(len(lines))] |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
maxcopy := rand.Intn(len(A)-1)+1 |
| 39 |
for copied, tocopy := 0, rand.Intn(2*len(A)/3); copied < tocopy; { |
| 40 |
l := rand.Intn(rand.Intn(maxcopy-1)+1) |
| 41 |
for a,b,n := rand.Intn(len(A)), rand.Intn(len(B)), 0; |
| 42 |
a < len(A) && b < len(B) && n < l; a,b,n = a+1,b+1,n+1 { |
| 43 |
B[b] = A[a] |
| 44 |
copied++ |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
for copied, tocopy := 0, rand.Intn(2*len(A)/3); copied < tocopy; { |
| 49 |
l := rand.Intn(rand.Intn(maxcopy-1)+1) |
| 50 |
for a,b,n := rand.Intn(len(A)), rand.Intn(len(B)), 0; |
| 51 |
a < len(A) && b < len(B) && n < l; a,b,n = a+1,b+1,n+1 { |
| 52 |
A[a] = B[b] |
| 53 |
copied++ |
| 54 |
} |
| 55 |
} |
| 56 |
return |
| 57 |
} |
| 58 |
|
| 59 |
func PrepareStringsToDiff(count, seed int) (As, Bs [][]string) { |
| 60 |
As = make([][]string, count) |
| 61 |
Bs = make([][]string, count) |
| 62 |
for i := range As { |
| 63 |
As[i], Bs[i] = prepareStrings(int64(i+seed)) |
| 64 |
} |
| 65 |
return |
| 66 |
} |