Created
May 17, 2018 03:51
-
-
Save mborawi/4ba4204f0a47f8b1de7d6227342da59d to your computer and use it in GitHub Desktop.
Generate csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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