Contains the Concourse pipeline definition for building a line-server container
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
879 B

  1. package main
  2. import (
  3. "math/rand"
  4. "time"
  5. )
  6. // from http://stackoverflow.com/a/31832326
  7. var src = rand.NewSource(time.Now().UnixNano())
  8. const letterBytes = "abcdefghijklmnopqrstuvwxyz1234567890"
  9. const (
  10. letterIdxBits = 6 // 6 bits to represent a letter index
  11. letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
  12. letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
  13. )
  14. func randomString(n int) string {
  15. b := make([]byte, n)
  16. // A src.Int63() generates 63 random bits, enough for letterIdxMax characters!
  17. for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; {
  18. if remain == 0 {
  19. cache, remain = src.Int63(), letterIdxMax
  20. }
  21. if idx := int(cache & letterIdxMask); idx < len(letterBytes) {
  22. b[i] = letterBytes[idx]
  23. i--
  24. }
  25. cache >>= letterIdxBits
  26. remain--
  27. }
  28. return string(b)
  29. }