package module
Version: v1.2.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2019 License: MIT Imports: 16 Imported by: 276



contributions welcome GoDoc Build Status Go 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


go get github.com/Pallinder/go-randomdata


package main

import (

func main() {
    // Print a random silly name

    // Print a male title

    // Print a female title

    // Print a title with random gender

    // Print a male first name

    // Print a female first name

    // Print a last name

    // Print a male name

    // Print a female name

    // Print a name with random gender

    // Print an email

    // Print a country with full text representation

    // Print a country using ISO 3166-1 alpha-2

    // Print a country using ISO 3166-1 alpha-3
    // Print BCP 47 language tag

    // Print a currency using ISO 4217

    // Print the name of a random city

    // Print the name of a random american state

    // Print the name of a random american state using two chars

    // Print an american sounding street name

    // Print an american sounding address

    // Print a random number >= 10 and < 20
    fmt.Println(randomdata.Number(10, 20))

    // Print a number >= 0 and < 20

    // Print a random float >= 0 and < 20 with decimal point 3
    fmt.Println(randomdata.Decimal(0, 20, 3))

    // Print a random float >= 10 and < 20
    fmt.Println(randomdata.Decimal(10, 20))

    // Print a random float >= 0 and < 20

    // Print a bool

    // Print a paragraph

    // Print a postal code

    // Print a set of 2 random numbers as a string
    fmt.Println(randomdata.StringNumber(2, "-"))

    // Print a set of 2 random 3-Digits numbers as a string
    fmt.Println(randomdata.StringNumberExt(2, "-", 3))

    // Print a random string sampled from a list of strings
    fmt.Println(randomdata.StringSample("my string 1", "my string 2", "my string 3"))

    // Print a valid random IPv4 address

    // Print a valid random IPv6 address

    // Print a browser's user agent string

    // Print a day

    // Print a month

    // Print full date like Monday 22 Aug 2016

    // Print full date <= Monday 22 Aug 2016

    // Print full date >= Monday 01 Aug 2016 and <= Monday 22 Aug 2016
    fmt.Println(randomdata.FullDateInRange("2016-08-01", "2016-08-22"))

    // Print phone number according to e.164

    // 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.go
    profile := 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 Britain
    // Get a random country-localised street name for USA

    // Get a random country-localised province for Great Britain
    // Get a random country-localised province for USA

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.


All the other contributors are listed here.



Package randomdata implements a bunch of simple ways to generate (pseudo) random data



View Source
const (
	Male         int = 0
	Female       int = 1
	RandomGender int = 2
View Source
const (
	Small int = 0
	Large int = 1
View Source
const (
	FullCountry      = 0
	TwoCharCountry   = 1
	ThreeCharCountry = 2
View Source
const (
	DateInputLayout  = "2006-01-02"
	DateOutputLayout = "Monday 2 Jan 2006"
View Source
const ALPHANUMERIC = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"


This section is empty.


func Address

func Address() string

Address returns an american style address

func Adjective

func Adjective() string

Adjective returns a random adjective

func Alphanumeric added in v1.2.0

func Alphanumeric(length int) string

Alphanumeric returns a random alphanumeric string consits of [0-9a-zA-Z].

func Boolean

func Boolean() bool

func BoundedDigits

func BoundedDigits(digits, low, high int) string

BoundedDigits generates a string of N random digits, padded with zeros if necessary. The output is restricted to the given range.

func City

func City() string

City returns a random city

func Country

func Country(countryStyle int64) string

Country returns a random country, countryStyle decides what kind of format the returned country will have

func Currency

func Currency() string

Currency returns a random currency under ISO 4217 format

func CustomRand

func CustomRand(randToUse *rand.Rand)

func Day

func Day() string

Day returns random day

func Decimal

func Decimal(numberRange ...int) float64

func Digits

func Digits(digits int) string

Digits generates a string of N random digits, padded with zeros if necessary.

func Email

func Email() string

Email returns a random email

func FirstName

func FirstName(gender int) string

FirstName returns a random first name, gender decides the gender of the name

func FullDate

func FullDate() string

FullDate returns full date

func FullDateInRange

func FullDateInRange(dateRange ...string) string

FullDateInRange returns a date string within a given range, given in the format "2006-01-02". If no argument is supplied it will return the result of randomdata.FullDate(). If only one argument is supplied it is treated as the max date to return. If a second argument is supplied it returns a date between (and including) the two dates. Returned date is in format "Monday 2 Jan 2006".

func FullName

func FullName(gender int) string

FullName returns a combination of FirstName LastName randomized, gender decides the gender of the name

func IpV4Address

func IpV4Address() string

IpV4Address returns a valid IPv4 address as string

func IpV6Address

func IpV6Address() string

IpV6Address returns a valid IPv6 address as net.IP

func LastName

func LastName() string

LastName returns a random last name

func Letters

func Letters(letters int) string

Letters generates a string of N random leters (A-Z).

func Locale

func Locale() string

func MacAddress

func MacAddress() string

MacAddress returns an mac address string

func Month

func Month() string

Month returns random month

func Noun

func Noun() string

Noun returns a random noun

func Number

func Number(numberRange ...int) int

Number returns a random number, if only one integer (n1) is supplied it returns a number in [0,n1) if a second argument is supplied it returns a number in [n1,n2)

func Paragraph

func Paragraph() string

Paragraph returns a random paragraph

func PhoneNumber

func PhoneNumber() string

func PostalCode

func PostalCode(countrycode string) string

PostalCode yields a random postal/zip code for the given 2-letter country code.

These codes are not guaranteed to refer to actually locations. They merely follow the correct format as far as letters and digits goes. Where possible, the function enforces valid ranges of letters and digits.

func ProvinceForCountry

func ProvinceForCountry(countrycode string) string

ProvinceForCountry returns a randomly selected province (state, county,subdivision ) name for a supplied country. If the country is not supported it will return an empty string.

func RandStringRunes

func RandStringRunes(n int) string

func SillyName

func SillyName() string

SillyName returns a silly name, useful for randomizing naming of things

func State

func State(typeOfState int) string

State returns a random american state

func Street

func Street() string

Street returns a random fake street name

func StreetForCountry

func StreetForCountry(countrycode string) string

StreetForCountry returns a random fake street name typical to the supplied country. If the country is not supported it will return an empty string.

func StringNumber

func StringNumber(numberPairs int, separator string) string

StringNumber returns a random number as a string

func StringNumberExt

func StringNumberExt(numberPairs int, separator string, numberOfDigits int) string

func StringSample

func StringSample(stringList ...string) string

StringSample returns a random string from a list of strings

func Timezone

func Timezone() string

func Title

func Title(gender int) string

Title returns a random title, gender decides the gender of the name

func UserAgentString

func UserAgentString() string


type Profile

type Profile struct {
	Gender string `json:"gender"`
	Name   struct {
		First string `json:"first"`
		Last  string `json:"last"`
		Title string `json:"title"`
	} `json:"name"`
	Location struct {
		Street   string `json:"street"`
		City     string `json:"city"`
		State    string `json:"state"`
		Postcode int    `json:"postcode"`
	} `json:"location"`

	Email string `json:"email"`
	Login struct {
		Username string `json:"username"`
		Password string `json:"password"`
		Salt     string `json:"salt"`
		Md5      string `json:"md5"`
		Sha1     string `json:"sha1"`
		Sha256   string `json:"sha256"`
	} `json:"login"`

	Dob        string `json:"dob"`
	Registered string `json:"registered"`
	Phone      string `json:"phone"`
	Cell       string `json:"cell"`

	ID struct {
		Name  string      `json:"name"`
		Value interface{} `json:"value"`
	} `json:"id"`

	Picture struct {
		Large     string `json:"large"`
		Medium    string `json:"medium"`
		Thumbnail string `json:"thumbnail"`
	} `json:"picture"`
	Nat string `json:"nat"`

func GenerateProfile

func GenerateProfile(gender int) *Profile

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL