random

package
v1.1.4-3 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

Random package contains implementation of random value generators that are used for functional as well as non-functional testing. Used to generate random objects and fill databases with unique objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TRandomArray

type TRandomArray struct{}

Random generator for array objects.

Examples:

value1 := RandomArray.pick([1, 2, 3, 4]); // Possible result: 3
var RandomArray *TRandomArray = &TRandomArray{}

func (*TRandomArray) Pick

func (c *TRandomArray) Pick(value interface{}) interface{}

Picks a random element from specified array. Parameters:

  • values: an array of any interface

Returns a randomly picked item.

type TRandomBoolean

type TRandomBoolean struct{}

Random generator for boolean values.

Example:

value1 := RandomBoolean.nextBoolean();    // Possible result: true
value2 := RandomBoolean.chance(1,3);      // Possible result: false
var RandomBoolean *TRandomBoolean = &TRandomBoolean{}

func (*TRandomBoolean) Chance

func (c *TRandomBoolean) Chance(chances int, maxChances int) bool

Calculates "chance" out of "max chances". Example: 1 chance out of 3 chances (or 33.3%)

  • chance: number - a chance proportional to maxChances.
  • maxChances: number - a maximum number of chances

func (*TRandomBoolean) NextBoolean

func (c *TRandomBoolean) NextBoolean() bool

Generates a random boolean value.

type TRandomDateTime

type TRandomDateTime struct{}

Random generator for Date time values.

Example:

value1 := RandomDateTime.nextDate(time.Parse(shortForm, "2007-Jan-01"), time.Parse(shortForm, "2010-Jan-01"));    // Possible result: 2008-01-03
value2 := RandomDateTime.nextDateTime(time.Parse(shortForm, "2006-Jan-01"), time.Parse(shortForm, "2017-Jan-01"));// Possible result: 2007-03-11 11:20:32
value3 := RandomDateTime.updateDateTime(time.Parse(shortForm, "2010-Jan-01"), );// Possible result: 2010-02-05 11:33:23
var RandomDateTime *TRandomDateTime = &TRandomDateTime{}

func (*TRandomDateTime) NextDate

func (c *TRandomDateTime) NextDate(min time.Time, max time.Time) time.Time

Generates a random Date in the range ['minYear', 'maxYear']. This method generate dates without time (or time set to 00:00:00)

Parameters:

  • min: time.Time - minimum range value
  • max: time.Time - maximum range value

Returns time.Time - a random Date value.

func (*TRandomDateTime) NextDateTime

func (c *TRandomDateTime) NextDateTime(min time.Time, max time.Time) time.Time

Generates a random Date and time in the range ['minYear', 'maxYear']. This method generate dates without time (or time set to 00:00:00)

Parameters:

  • min: time.Time minimum range value
  • max: time.Time - maximum range value

Returns time.Time a random Date and Time value.

func (*TRandomDateTime) UpdateDateTime

func (c *TRandomDateTime) UpdateDateTime(value time.Time, interval int64) time.Time

type TRandomDouble

type TRandomDouble struct{}

Random generator for double values.

Example:

value1 := RandomDouble.nextDouble(5, 10);     // Possible result: 7.3
value2 := RandomDouble.nextDouble(10);        // Possible result: 3.7
value3 := RandomDouble.updateDouble(10, 3);   // Possible result: 9.2
var RandomDouble *TRandomDouble = &TRandomDouble{}

func (*TRandomDouble) NextDouble

func (c *TRandomDouble) NextDouble(min float64, max float64) float64

Generates a random double value in the range ['min', 'max']. Parameters:

  • min: float64 - minimum range value
  • max: float64 - max range value

Returns: float64 - a random value.

func (*TRandomDouble) UpdateDouble

func (c *TRandomDouble) UpdateDouble(value float64, interval float64) float64

Updates (drifts) a double value within specified range defined Parameters:

  • value: float64 - value to drift.
  • interval: float64 - a range to drift. Default: 10% of the value

Returns float64

type TRandomFloat

type TRandomFloat struct{}

Random generator for float values.

Examples:

value1 := RandomFloat.nextFloat(5, 10);     // Possible result: 7.3
value2 := RandomFloat.nextFloat(10);        // Possible result: 3.7
value3 := RandomFloat.updateFloat(10, 3);   // Possible result: 9.2
var RandomFloat *TRandomFloat = &TRandomFloat{}

func (*TRandomFloat) NextFloat

func (c *TRandomFloat) NextFloat(min float32, max float32) float32

Generates a float in the range ['min', 'max']. If 'max' is omitted, then the range will be set to [0, 'min'].

Parameters:

  • min: float32 - minimum value of the float that will be generated. If 'max' is omitted, then 'max' is set to 'min' and 'min' is set to 0.
  • max: float32 - maximum value of the float that will be generated. Defaults to 'min' if omitted.

Returns generated random float32 value.

func (*TRandomFloat) UpdateFloat

func (c *TRandomFloat) UpdateFloat(value float32, interval float32) float32

Updates (drifts) a float value within specified range defined Parameters:

  • value: float32 - value to drift.
  • interval: float32 - a range. Default: 10% of the value

Returns float32

type TRandomInteger

type TRandomInteger struct{}

Random generator for integer values. Example:

value1 := RandomInteger.nextInteger(5, 10);     // Possible result: 7
value2 := RandomInteger.nextInteger(10);        // Possible result: 3
value3 := RandomInteger.updateInteger(10, 3);   // Possible result: 9
var RandomInteger *TRandomInteger = &TRandomInteger{}

func (*TRandomInteger) NextInteger

func (c *TRandomInteger) NextInteger(min int, max int) int

func (*TRandomInteger) Sequence

func (c *TRandomInteger) Sequence(min int, max int) []int

Generates a random sequence of integers starting from 0 like: [0,1,2,3...??]

Parameters:

  • min: int - minimum value of the integer that will be generated. If 'max' is omitted, then 'max' is set to 'min' and 'min' is set to 0.
  • max: int - maximum value of the int that will be generated. Defaults to 'min' if omitted.

Returns generated array of integers.

func (*TRandomInteger) UpdateInteger

func (c *TRandomInteger) UpdateInteger(value int, interval int) int

Updates (drifts) a integer value within specified range defined

Parameters:

  • value: int - a integer value to drift.
  • interval:int - a range. Default: 10% of the value

Returns int

type TRandomLong

type TRandomLong struct{}

Random generator for integer values. Example:

value1 := RandomLong.nextLong(5, 10);     // Possible result: 7
value2 := RandomLong.nextLong(10);        // Possible result: 3
value3 := RandomLong.updateLong(10, 3);   // Possible result: 9
var RandomLong *TRandomLong = &TRandomLong{}

func (*TRandomLong) NextLong

func (c *TRandomLong) NextLong(min int64, max int64) int64

Generates a integer in the range ['min', 'max']. If 'max' is omitted, then the range will be set to [0, 'min'].

Parameters:

  • min: int64 - minimum value of the integer that will be generated. If 'max' is omitted, then 'max' is set to 'min' and 'min' is set to 0.
  • max: int64 - maximum value of the int that will be generated. Defaults to 'min' if omitted.

Returns generated random int64 value.

func (*TRandomLong) Sequence

func (c *TRandomLong) Sequence(min int64, max int64) []int64

Generates a random sequence of integers starting from 0 like: [0,1,2,3...??]

Parameters:

  • min: int64 - minimum value of the integer that will be generated. If 'max' is omitted, then 'max' is set to 'min' and 'min' is set to 0.
  • max: int64 - maximum value of the int that will be generated. Defaults to 'min' if omitted.

Returns generated array of int64.

func (*TRandomLong) UpdateLong

func (c *TRandomLong) UpdateLong(value int64, interval int64) int64

Updates (drifts) a integer value within specified range defined

Parameters:

  • value: int - a integer value to drift.
  • interval:int - a range. Default: 10% of the value

Returns int

type TRandomString

type TRandomString struct{}

Random generator for string values.

Example:

value1 := RandomString.pickChar("ABC");     // Possible result: "C"
value2 := RandomString.pick(["A","B","C"]); // Possible result: "gBW"
var RandomString *TRandomString = &TRandomString{}

func (*TRandomString) Distort

func (c *TRandomString) Distort(value string) string

func (*TRandomString) NextAlphaChar

func (c *TRandomString) NextAlphaChar() byte

Generates random alpha characted [A-Za-z]

Returns a random characted.

func (*TRandomString) NextString

func (c *TRandomString) NextString(minLength int, maxLength int) string

Generates a random string, consisting of upper and lower case letters (of the English alphabet), digits (0-9), and symbols ("_,.:-/.[].{},#-!,$=%.+^.&*-() ").

Parameters:

  • minLength: int - minimum string length.
  • maxLength: int - maximum string length.

Returns a random string.

func (*TRandomString) Pick

func (c *TRandomString) Pick(values []string) string

Picks a random string from an array of string.

Parameters:

  • values: string[] strings to pick from.

Returns a randomly picked string.

func (*TRandomString) PickChar

func (c *TRandomString) PickChar(values string) byte

Picks a random character from a string.

Parameters:

  • values: string to pick a char from

Returnsa randomly picked char.

type TRandomText

type TRandomText struct{}

Random generator for various text values like names, addresses or phone numbers.

Example:

value1 := RandomText.FullName();     	// Possible result: "Segio"
value2 := RandomText.Verb();      	// Possible result: "Run"
value3 := RandomText.Text(50);    	// Possible result: "Run jorge. Red high scream?"
var RandomText *TRandomText = &TRandomText{}

func (*TRandomText) Adjective

func (c *TRandomText) Adjective() string

Return string with random adjective

func (*TRandomText) Color

func (c *TRandomText) Color() string

Return string with random color

func (*TRandomText) Email

func (c *TRandomText) Email() string

Return string with random email

func (*TRandomText) FullName

func (c *TRandomText) FullName() string

Return string with random full name

func (*TRandomText) Phone

func (c *TRandomText) Phone() string

Return string with random phone

func (*TRandomText) Phrase

func (c *TRandomText) Phrase(min int, max int) string

Return string with random phrase

func (*TRandomText) Stuff

func (c *TRandomText) Stuff() string

Return string with random stuff

func (*TRandomText) Text

func (c *TRandomText) Text(min int, max int) string

Return string with random text

func (*TRandomText) Verb

func (c *TRandomText) Verb() string

Return string with random verb

func (*TRandomText) Word

func (c *TRandomText) Word() string

Return string with random word

func (*TRandomText) Words

func (c *TRandomText) Words(min int, max int) string

Return string with random words

Jump to

Keyboard shortcuts

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