currency.go 936 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package gofakeit
  2. import (
  3. "math"
  4. "math/rand"
  5. "github.com/brianvoe/gofakeit/data"
  6. )
  7. // CurrencyInfo is a struct of currency information
  8. type CurrencyInfo struct {
  9. Short string
  10. Long string
  11. }
  12. // Currency will generate a struct with random currency information
  13. func Currency() *CurrencyInfo {
  14. index := rand.Intn(len(data.Data["currency"]["short"]))
  15. return &CurrencyInfo{
  16. Short: data.Data["currency"]["short"][index],
  17. Long: data.Data["currency"]["long"][index],
  18. }
  19. }
  20. // CurrencyShort will generate a random short currency value
  21. func CurrencyShort() string {
  22. return getRandValue([]string{"currency", "short"})
  23. }
  24. // CurrencyLong will generate a random long currency name
  25. func CurrencyLong() string {
  26. return getRandValue([]string{"currency", "long"})
  27. }
  28. // Price will take in a min and max value and return a formatted price
  29. func Price(min, max float64) float64 {
  30. return math.Floor(randFloat64Range(min, max)*100) / 100
  31. }