Skip to content

Instantly share code, notes, and snippets.

@mborawi
Created May 17, 2018 03:51
Show Gist options
  • Select an option

  • Save mborawi/4ba4204f0a47f8b1de7d6227342da59d to your computer and use it in GitHub Desktop.

Select an option

Save mborawi/4ba4204f0a47f8b1de7d6227342da59d to your computer and use it in GitHub Desktop.
Generate csv
package main
import (
"bufio"
"fmt"
"math/rand"
"os"
"time"
"github.com/icrowley/fake"
)
func main() {
N := 20000
fmt.Println("creating fake data")
f, err := os.Create("dummy.csv")
if err != nil {
fmt.Println(err)
return
}
w := bufio.NewWriter(f)
for i := 1; i <= N; i++ {
fname := fake.FirstName()
month := rand.Intn(12) + 1
day := rand.Intn(27) + 1
startDate := time.Date(2018, time.Month(month), day, 0, 0, 0, 0, time.UTC)
duration := time.Hour * 24 * time.Duration(rand.Intn(4)+1)
FinishDate := startDate.Add(duration)
fmt.Fprintf(w, "%d,%s,%s,%s\n", i, fname, startDate.Format("2006-01-02"), FinishDate.Format("2006-01-02"))
}
w.Flush()
f.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment