46 lines
871 B
Go
46 lines
871 B
Go
package corpus
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
)
|
|
|
|
func MakeCorpus() []string {
|
|
// Generate data
|
|
lineLength := 100
|
|
var lines []string
|
|
for i := 1; i <= 1000; i++ {
|
|
lines = append(lines, makeLine(i, lineLength))
|
|
}
|
|
|
|
// Randomize
|
|
for i := range lines {
|
|
j := rand.Intn(i + 1)
|
|
lines[i], lines[j] = lines[j], lines[i]
|
|
}
|
|
|
|
return lines
|
|
}
|
|
|
|
func makeLine(line int, lineLength int) string {
|
|
var key string = fmt.Sprintf("%06d", line)
|
|
lineLength = lineLength - len(key)
|
|
|
|
var firstLen int = rand.Intn(lineLength)
|
|
var secondLen int = lineLength - firstLen
|
|
|
|
return randomString(firstLen) + key + randomString(secondLen)
|
|
}
|
|
|
|
func randomString(n int) string {
|
|
var letters = []rune("abcdefghijklmnopqrstuvwxyz")
|
|
var length int = len(letters)
|
|
|
|
s := make([]rune, n)
|
|
for i := range s {
|
|
s[i] = letters[rand.Intn(length)]
|
|
}
|
|
|
|
return string(s)
|
|
}
|