time_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package main
  2. import (
  3. "fmt"
  4. "math/rand"
  5. "strings"
  6. "testing"
  7. "time"
  8. )
  9. func Test_getTime(t *testing.T) {
  10. now := time.Now().Add(-21 * time.Hour)
  11. d := ""
  12. for i := 30; i > 0; i-- {
  13. num := rand.Intn(24)
  14. day := now.AddDate(0, 0, -i).Add(time.Duration(num) * time.Hour)
  15. for j := 0; j < 3; j++ {
  16. a := rand.Intn(10)
  17. //fmt.Println(day.Add(time.Duration(j*22)*time.Minute).Format(DateFmtYYYYMMDDHHmmss), a)
  18. d = fmt.Sprintf("%s (%s,%d)", d, day.Add(time.Duration(j*22)*time.Minute).Format(DateFmtYYYYMMDDHHmmss), a)
  19. }
  20. }
  21. d = fmt.Sprintf("insert into qwert values%s", d)
  22. fmt.Println(d)
  23. }
  24. func Test_getAccount(t *testing.T) {
  25. s := fmt.Sprintf("iaa%s", GetRandomString(39))
  26. t.Log(s)
  27. }
  28. func GetRandomString(l int) string {
  29. now := time.Now().Format("060102150405.000")
  30. nowFmt := strings.Replace(now, ".", "", -1)
  31. str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  32. bytes := []byte(str)
  33. var result []byte
  34. j := 0
  35. r := rand.New(rand.NewSource(time.Now().UnixNano() + int64(rand.Intn(100))))
  36. for i := 0; i < l; i++ {
  37. if i%2 != 0 && j < len(nowFmt) {
  38. result = append(result, nowFmt[j])
  39. j++
  40. } else {
  41. result = append(result, bytes[r.Intn(len(bytes))])
  42. }
  43. }
  44. return string(result)
  45. }