Documentation
¶
Overview ¶
Package randomdata implements a bunch of simple ways to generate (pseudo) random data
Example ¶
r := FromSeed(1234) // Print an int from the half-open interval [0, 10) fmt.Println(r.Intn(10)) // Print a float64 from the half-open interval [0.0, 1.0) fmt.Println(r.Float64()) // Print a random bool fmt.Println(r.Boolean()) // Print a duration fmt.Println(r.Duration(24 * time.Hour).Hours()) // Print a time between now and Tomorrow fmt.Println(r.Time(time.Now(), 24*time.Hour)) // Print a time range now and Tomorrow fmt.Println(r.TimeRange(time.Now(), 24*time.Hour)) // Print a male title fmt.Println(r.FirstName(Male)) // Print a female title fmt.Println(r.FirstName(Female)) // Print a title with random gender fmt.Println(r.FirstName(RandomGender)) // Print a male first name fmt.Println(r.FirstName(Male)) // Print a female first name fmt.Println(r.FirstName(Female)) // Print a first name with random gender fmt.Println(r.FirstName(RandomGender)) // Print a last name fmt.Println(r.LastName()) // Print a male name fmt.Println(r.FullName(Male)) // Print a female name fmt.Println(r.FullName(Female)) // Print a name with random gender fmt.Println(r.FullName(RandomGender)) // Print a random email fmt.Println(r.Email()) // Print a country with full text representation fmt.Println(r.Country(FullCountry)) // Print a country using ISO 3166-1 alpha-3 fmt.Println(r.Country(ThreeCharCountry)) // Print a country using ISO 3166-1 alpha-2 fmt.Println(r.Country(TwoCharCountry)) // Print a currency using ISO 4217 fmt.Println(r.Currency()) // Print the name of a random city fmt.Println(r.City()) // Print the name of a random american state fmt.Println(r.State(Large)) // Print the name of a random american state using two letters fmt.Println(r.State(Small)) // Print a random number >= 10 and <= 20 fmt.Println(r.Number(10, 20)) // Print a number >= 0 and <= 20 fmt.Println(r.Number(20)) // Print a random float >= 0 and <= 20 with decimal point 3 fmt.Println(r.Decimal(0, 20, 3)) // Print a random float >= 10 and <= 20 fmt.Println(r.Decimal(10, 20)) // Print a random float >= 0 and <= 20 fmt.Println(r.Decimal(20)) // Print a paragraph fmt.Println(r.Paragraph()) // Print a random postalcode from Sweden fmt.Println(r.PostalCode("SE")) // Print a random american sounding street name fmt.Println(r.Street()) // Print a random american address fmt.Println(r.Address()) // Print a random string of numbers fmt.Println(r.StringNumber(2, "-")) // Print a set of 2 random 3-Digits numbers as a string fmt.Println(r.StringNumberExt(2, "-", 3)) // Print a random IPv4 address fmt.Println(r.IpV4Address()) // Print a random IPv6 address fmt.Println(r.IpV6Address()) // Print a random day fmt.Println(r.Day()) // Print a month fmt.Println(r.Month()) // Print full date fmt.Println(r.FullDate())
Index ¶
- Constants
- type Profile
- type Rand
- func (r *Rand) Address() string
- func (r *Rand) Adjective() string
- func (r *Rand) Alphanumeric(length int) string
- func (r *Rand) Boolean() bool
- func (r *Rand) BoundedDigits(digits, low, high int) string
- func (r *Rand) City() string
- func (r *Rand) Country(countryStyle int64) string
- func (r *Rand) Currency() string
- func (r *Rand) Day() string
- func (r *Rand) Decimal(numberRange ...int) float64
- func (r *Rand) Digits(digits int) string
- func (r *Rand) Duration(maxDuration time.Duration) time.Duration
- func (r *Rand) Email() string
- func (r *Rand) FirstName(gender int) string
- func (r *Rand) Float64() float64
- func (r *Rand) FullDate() string
- func (r *Rand) FullDateInRange(dateRange ...string) string
- func (r *Rand) FullName(gender int) string
- func (r *Rand) GenerateProfile(gender int) *Profile
- func (r *Rand) Intn(n int) int
- func (r *Rand) IpV4Address() string
- func (r *Rand) IpV6Address() string
- func (r *Rand) LastName() string
- func (r *Rand) Letters(letters int) string
- func (r *Rand) Locale() string
- func (r *Rand) MacAddress() string
- func (r *Rand) Month() string
- func (r *Rand) Noun() string
- func (r *Rand) Number(numberRange ...int) int
- func (r *Rand) Paragraph() string
- func (r *Rand) PhoneNumber() string
- func (r *Rand) PostalCode(countrycode string) string
- func (r *Rand) ProvinceForCountry(countrycode string) string
- func (r *Rand) RandStringRunes(n int) string
- func (r *Rand) SillyName() string
- func (r *Rand) State(typeOfState int) string
- func (r *Rand) Street() string
- func (r *Rand) StreetForCountry(countrycode string) string
- func (r *Rand) StringFrom(source []string) string
- func (r *Rand) StringNumber(numberPairs int, separator string) string
- func (r *Rand) StringNumberExt(numberPairs int, separator string, numberOfDigits int) string
- func (r *Rand) Time(t time.Time, timeRange time.Duration) time.Time
- func (r *Rand) TimeRange(t time.Time, timeRange time.Duration) (time.Time, time.Time)
- func (r *Rand) Timezone() string
- func (r *Rand) Title(gender int) string
- func (r *Rand) UserAgentString() string
Examples ¶
Constants ¶
const ( Male int = 0 Female int = 1 RandomGender int = 2 )
const ( Small int = 0 Large int = 1 )
const ( FullCountry = 0 TwoCharCountry = 1 ThreeCharCountry = 2 )
const ( DateInputLayout = "2006-01-02" DateOutputLayout = "Monday 2 Jan 2006" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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"` }
Profile contains all the data related to a complete profil.
type Rand ¶
type Rand struct {
// contains filtered or unexported fields
}
Rand is a source of random numbers.
func (*Rand) Alphanumeric ¶
Alphanumeric returns a random alphanumeric string consits of [0-9a-zA-Z].
func (*Rand) BoundedDigits ¶
BoundedDigits generates a string of N random digits, padded with zeros if necessary. The output is restricted to the given range.
func (*Rand) Country ¶
Country returns a random country, countryStyle decides what kind of format the returned country will have.
func (*Rand) Duration ¶
Duration returns a random duration between 0 and the specified max duration.
func (*Rand) FirstName ¶
FirstName returns a random first name, gender decides the gender of the name.
func (*Rand) Float64 ¶
Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).
func (*Rand) FullDateInRange ¶
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 (*Rand) FullName ¶
FullName returns a combination of FirstName LastName randomized, gender decides the gender of the name.
func (*Rand) GenerateProfile ¶
GenerateProfile generates a full profile.
func (*Rand) Intn ¶
Intn returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n). It panics if n <= 0.
func (*Rand) IpV4Address ¶
IpV4Address returns a valid IPv4 address as string.
func (*Rand) IpV6Address ¶
IpV6Address returns a valid IPv6 address as net.IP.
func (*Rand) MacAddress ¶
MacAddress returns an mac address string.
func (*Rand) Number ¶
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 (*Rand) PhoneNumber ¶
PhoneNumber returns a random phone number.
func (*Rand) PostalCode ¶
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 (*Rand) ProvinceForCountry ¶
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 (*Rand) RandStringRunes ¶
RandStringRunes generates random runes.
func (*Rand) StreetForCountry ¶
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 (*Rand) StringFrom ¶
StringFrom returns a random element of a slice.
func (*Rand) StringNumber ¶
StringNumber returns a random number as a string.
func (*Rand) StringNumberExt ¶
StringNumberExt returns a random number as a string.
func (*Rand) Time ¶
Time returns a random time between the given time and within a given duration time range.
func (*Rand) TimeRange ¶
TimeRange returns a random time interval between the given time and within a given time range.
func (*Rand) UserAgentString ¶
UserAgentString returns a user agent used to browse the web.