Skip to content

Instantly share code, notes, and snippets.

@okkez

okkez/go.mod

Created Dec 27, 2020
Embed
What would you like to do?
module github.com/okkez/csv-aggregation-example/generator
go 1.14
require github.com/bxcodec/faker/v3 v3.5.0
package main
import(
"fmt"
"math/rand"
"strings"
"github.com/bxcodec/faker/v3"
)
const lines = 3000000
var serviceNames []string
func randomCost() float32 {
return rand.Float32() * 100
}
func init() {
for i := 0; i < 20; i++ {
serviceNames = append(serviceNames, faker.Username())
}
}
func main() {
NumberOfServiceNames := len(serviceNames)
headerNames := []string{
"id",
"name",
"description",
"cost",
}
headerLine := strings.Join(headerNames, ",")
fmt.Println(headerLine)
initialID := rand.Uint32()
for i := 0; i < lines; i++ {
line := fmt.Sprintf("%d,%s,%s,%.3f", initialID + uint32(i), serviceNames[rand.Int() % NumberOfServiceNames], faker.Sentence(), randomCost())
fmt.Println(line)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment