Skip to content

Instantly share code, notes, and snippets.

@okkez
Created December 27, 2020 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okkez/05ffa0df08cf49014f460eb2e8543698 to your computer and use it in GitHub Desktop.
Save okkez/05ffa0df08cf49014f460eb2e8543698 to your computer and use it in GitHub Desktop.
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