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
|
package tester
import (
"math/rand"
"time"
)
func prepareStrings(seed int64) (A, B []string) {
if seed == -1 {
seed = time.Now().UnixNano()
}
rand.Seed(seed)
// Generate 4000 random lines
lines := [4000]string{}
for i := range lines {
l := rand.Intn(100)
p := make([]byte, l)
rand.Read(p)
lines[i] = string(p)
}
// Generate two 4000 lines documents by picking some lines at random
A = make([]string, 4000)
B = make([]string, len(A))
for i := range A {
// make the first 50 lines more likely to appear
if rand.Intn(100) < 40 {
A[i] = lines[rand.Intn(50)]
} else {
A[i] = lines[rand.Intn(len(lines))]
}
if rand.Intn(100) < 40 {
B[i] = lines[rand.Intn(50)]
} else {
B[i] = lines[rand.Intn(len(lines))]
}
}
// Do some copies from A to B
maxcopy := rand.Intn(len(A)-1)+1
for copied, tocopy := 0, rand.Intn(2*len(A)/3); copied < tocopy; {
l := rand.Intn(rand.Intn(maxcopy-1)+1)
for a,b,n := rand.Intn(len(A)), rand.Intn(len(B)), 0;
a < len(A) && b < len(B) && n < l; a,b,n = a+1,b+1,n+1 {
B[b] = A[a]
copied++
}
}
// And some from B to A
for copied, tocopy := 0, rand.Intn(2*len(A)/3); copied < tocopy; {
l := rand.Intn(rand.Intn(maxcopy-1)+1)
for a,b,n := rand.Intn(len(A)), rand.Intn(len(B)), 0;
a < len(A) && b < len(B) && n < l; a,b,n = a+1,b+1,n+1 {
A[a] = B[b]
copied++
}
}
return
}
func PrepareStringsToDiff(count, seed int) (As, Bs [][]string) {
As = make([][]string, count)
Bs = make([][]string, count)
for i := range As {
As[i], Bs[i] = prepareStrings(int64(i+seed))
}
return
}
|