Skip to content

Repository files navigation

go-randomdata

contributions welcomeGoDocBuild StatusGo Report Card

randomdata is a tiny help suite for generating random data such as

  • first names (male or female)
  • last names
  • full names (male or female)
  • country names (full name or iso 3166.1 alpha-2 or alpha-3)
  • locales / language tags (bcp-47)
  • random email address
  • city names
  • American state names (two chars or full)
  • random numbers (in an interval)
  • random paragraphs
  • random bool values
  • postal- or zip-codes formatted for a range of different countries.
  • american sounding addresses / street names
  • silly names - suitable for names of things
  • random days
  • random months
  • random full date
  • random full profile
  • random date inside range
  • random phone number

Installation

go get github.com/Pallinder/go-randomdata

Usage

package main
import (
"fmt""github.com/Pallinder/go-randomdata"
)
funcmain() {
// Print a random silly namefmt.Println(randomdata.SillyName())
// Print a male titlefmt.Println(randomdata.Title(randomdata.Male))
// Print a female titlefmt.Println(randomdata.Title(randomdata.Female))
// Print a title with random genderfmt.Println(randomdata.Title(randomdata.RandomGender))
// Print a male first namefmt.Println(randomdata.FirstName(randomdata.Male))
// Print a female first namefmt.Println(randomdata.FirstName(randomdata.Female))
// Print a last namefmt.Println(randomdata.LastName())
// Print a male namefmt.Println(randomdata.FullName(randomdata.Male))
// Print a female namefmt.Println(randomdata.FullName(randomdata.Female))
// Print a name with random genderfmt.Println(randomdata.FullName(randomdata.RandomGender))
// Print an emailfmt.Println(randomdata.Email())
// Print a country with full text representationfmt.Println(randomdata.Country(randomdata.FullCountry))
// Print a country using ISO 3166-1 alpha-2fmt.Println(randomdata.Country(randomdata.TwoCharCountry))
// Print a country using ISO 3166-1 alpha-3fmt.Println(randomdata.Country(randomdata.ThreeCharCountry))
// Print BCP 47 language tagfmt.Println(randomdata.Locale())
// Print a currency using ISO 4217fmt.Println(randomdata.Currency())
// Print the name of a random cityfmt.Println(randomdata.City())
// Print the name of a random american statefmt.Println(randomdata.State(randomdata.Large))
// Print the name of a random american state using two charsfmt.Println(randomdata.State(randomdata.Small))
// Print an american sounding street namefmt.Println(randomdata.Street())
// Print an american sounding addressfmt.Println(randomdata.Address())
// Print a random number >= 10 and < 20fmt.Println(randomdata.Number(10, 20))
// Print a number >= 0 and < 20fmt.Println(randomdata.Number(20))
// Print a random float >= 0 and < 20 with decimal point 3fmt.Println(randomdata.Decimal(0, 20, 3))
// Print a random float >= 10 and < 20fmt.Println(randomdata.Decimal(10, 20))
// Print a random float >= 0 and < 20fmt.Println(randomdata.Decimal(20))
// Print a boolfmt.Println(randomdata.Boolean())
// Print a paragraphfmt.Println(randomdata.Paragraph())
// Print a postal codefmt.Println(randomdata.PostalCode("SE"))
// Print a set of 2 random numbers as a stringfmt.Println(randomdata.StringNumber(2, "-"))
// Print a set of 2 random 3-Digits numbers as a stringfmt.Println(randomdata.StringNumberExt(2, "-", 3))
// Print a random string sampled from a list of stringsfmt.Println(randomdata.StringSample("my string 1", "my string 2", "my string 3"))
// Print a valid random IPv4 addressfmt.Println(randomdata.IpV4Address())
// Print a valid random IPv6 addressfmt.Println(randomdata.IpV6Address())
// Print a browser's user agent stringfmt.Println(randomdata.UserAgentString())
// Print a dayfmt.Println(randomdata.Day())
// Print a monthfmt.Println(randomdata.Month())
// Print full date like Monday 22 Aug 2016fmt.Println(randomdata.FullDate())
// Print full date <= Monday 22 Aug 2016fmt.Println(randomdata.FullDateInRange("2016-08-22"))
// Print full date >= Monday 01 Aug 2016 and <= Monday 22 Aug 2016fmt.Println(randomdata.FullDateInRange("2016-08-01", "2016-08-22"))
// Print phone number according to e.164fmt.Println(randomdata.PhoneNumber())
// Get a complete and randomised profile of data generally used for users// There are many fields in the profile to use check the Profile struct definition in fullprofile.goprofile:=randomdata.GenerateProfile(randomdata.Male|randomdata.Female|randomdata.RandomGender)
fmt.Printf("The new profile's username is: %s and password (md5): %s\n", profile.Login.Username, profile.Login.Md5)
// Get a random country-localised street name for Great Britainfmt.Println(randomdata.StreetForCountry("GB"))
// Get a random country-localised street name for USAfmt.Println(randomdata.StreetForCountry("US"))
// Get a random country-localised province for Great Britainfmt.Println(randomdata.ProvinceForCountry("GB"))
// Get a random country-localised province for USAfmt.Println(randomdata.ProvinceForCountry("US"))
}

Versioning / Release Strategy

Go-Randomdata follows Semver

You can find current releases tagged under the releases section.

The CHANGELOG.md file contains the changelog of the project.

Contributors

All the other contributors are listed here.

About

A tiny generator of random data for golang, also known as a faker

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages