CEL

Functions

Standard functions included in the Twisp CEL runtime.

CEL provides function invocation within expressions to perform operations and computations. Twisp includes a number of predefined extensions to the CEL runtime environment for computation within ledger transactions.

Packages

The included package functions are:

  1. Strongly-typed: The function signatures of a package require that the arguments provided have the expected types.
  2. Side-effect-free: Package functions only calculate an output based on the inputs given.

The Twisp CEL runtime has been extended with the following packages and their respective function signatures.

decimal

func decimal.Abs(x decimal) decimal, error

Abs calculates |x| (the absolute value of x).

func decimal.Add(x decimal, y decimal) decimal, error

Add calculates the sum of x+y.

func decimal.Cbrt(x decimal) decimal, error

Cbrt calculates the cube root of x.

func decimal.Ceil(x decimal) decimal, error

Ceil calculates smallest integer >= x.

func decimal.Cmp(x decimal, y decimal) decimal, error

Cmp compares x and y and calculates:

-1 if x <  y
 0 if x == y
+1 if x >  y

This comparison respects the normal rules of special values (like NaN), and does not compare them.

func decimal.Exp(x decimal, precision uint32) decimal, error

Exp calculates e**x.

func decimal.Ln(x decimal) decimal, error

Ln calculates the natural log of x.

func decimal.Log10(x decimal) decimal, error

Log10 calculates the base 10 log of x.

func decimal.Mul(x decimal, y decimal) decimal, error

Mul calculates the product x*y.

func decimal.Neg(x decimal) decimal, error

Neg calculates -x.

func decimal.Pow(x decimal, y decimal) decimal, error

Pow calculates x**y.

func decimal.Quantize(x decimal, exp int, precision uint32) decimal, error

Quantize calculates and rounds x as necessary so it is represented with exponent exp.

func decimal.Quo(x decimal, y decimal, precision uint32) decimal, error

Quo calculates the quotient x/y for y != 0.

func decimal.QuoInteger(x decimal, y decimal, precision uint32) decimal, error

QuoInteger calculates the integer part of the quotient x/y

func decimal.Reduce(x decimal) decimal, error

Reduce calculates x with all trailing zeros removed.

func decimal.Rem(x decimal, y decimal, precision uint32) decimal, error

Rem calculates the remainder part of the quotient x/y.

func decimal.Sqrt(x decimal) decimal, error

Sqrt calculates the square root of x. Sqrt uses the Babylonian method for computing the square root, which uses O(log p) steps for p digits of precision.

func decimal.Sub(x decimal, y decimal) decimal, error

Sub calculates the difference x-y.

func decimal.Round(x decimal, mode string, digits int) decimal, error

Round rounds x to the number of digits with the specified rounding mode. Supported rounding modes:

down

Rounds toward 0; truncate.

half_up

Rounds up if the digits are >= 0.5.

half_even

Rounds up if the digits are > 0.5. If the digits are equal to 0.5, it rounds up if the previous digit is odd, always producing an even digit.

ceiling

Rounds towards +Inf: rounds up if digits are > 0 and the number is positive.

floor

Rounds towards -Inf: rounds up if digits are > 0 and the number is negative.

half_down

Rounds up if the digits are > 0.5.

up

Rounds away from 0.

05up

Rounds zero or five away from 0; same as round-up, except that rounding up only occurs if the digit to be rounded up is 0 or 5.

finance

func finance.DaysDifference(date1 int64, date2 int64, basis int) int

DaysDifference returns the difference of days between two dates based on a daycount basis. Date1 and date2 are UNIX timestamps (seconds). "basis" must be one of: 0 = US(NASD) 30/360, 1 = Actual/actual, 2 = Actual/360, 3 = Actual/365, 4 = European 30/360.

func finance.DaysPerYear(year int, basis int) int

DaysPerYear returns the number of days in the year based on a daycount basis. "basis" must be one of: 0 = US(NASD) 30/360, 1 = Actual/actual, 2 = Actual/360, 3 = Actual/365, 4 = European 30/360.

func finance.DepreciationFixedDeclining(cost float64, salvage float64, life int, period int, month int) float64, error

DepreciationFixedDeclining returns the depreciation of an asset using the fixed-declining balance method. Excel equivalent: DB. "basis" must be one of: 0 = US(NASD) 30/360, 1 = Actual/actual, 2 = Actual/360, 3 = Actual/365, 4 = European 30/360.

func finance.DepreciationSYD(cost float64, salvage float64, life int, per int) float64

DepreciationSYD returns the depreciation for an asset in a given period using the sum-of-years' digits method. Excel equivalent: SYD.

func finance.DepreciationStraightLine(cost float64, salvage float64, life int) float64, error

DepreciationStraightLine returns the straight-line depreciation of an asset for each period. Excel equivalent: SLN.

func finance.DiscountRate(settlement int64, maturity int64, price float64, redemption float64, basis int) float64

DiscountRate returns the discount rate for a bond "settlement" is the unix timestamp (seconds) for the settlement date. "maturity" is the unix timestamp (seconds) for the maturity date. "price" is the bond's price per $100 face value. "redemption" is the bond's redemption value per $100 face value. Excel equivalent: DISC. "basis" must be one of: 0 = US(NASD) 30/360, 1 = Actual/actual, 2 = Actual/360, 3 = Actual/365, 4 = European 30/360.

func finance.EffectiveRate(nominal float64, numPeriods int) float64, error

EffectiveRate returns the effective interest rate given the nominal rate and the number of compounding payments per year. Excel equivalent: EFFECT.

func finance.FutureValue(rate float64, numPeriods int, pmt float64, pv float64, paymentType int)fv float64, err error

FutureValue returns the Future Value of a cash flow with constant payments and interest rate (annuities). Excel equivalent: FV. "paymentType" must be one of: 0 = PayEnd, 1 = PayBegin.

func finance.InterestPayment(rate float64, period int, numPeriods int, pv float64, fv float64, paymentType int) float64, error

InterestPayment returns the interest payment for a given period for a cash flow with constant periodic payments (annuities). Excel equivalent: IMPT. "paymentType" must be one of: 0 = PayEnd, 1 = PayBegin.

func finance.NominalRate(effectiveRate float64, numPeriods int) float64, error

NominalRate returns the nominal interest rate given the effective rate and the number of compounding payments per year. Excel equivalent: NOMINAL.

func finance.Payment(rate float64, numPeriods int, pv float64, fv float64, paymentType int)pmt float64, err error

Payment returns the constant payment (annuity) for a cash flow with a constant interest rate. Excel equivalent: PMT. "paymentType" must be one of: 0 = PayEnd, 1 = PayBegin.

func finance.Periods(rate float64, pmt float64, pv float64, fv float64, paymentType int)numPeriods float64, err error

Periods returns the number of periods for a cash flow with constant periodic payments (annuities), and interest rate. Excel equivalent: NPER. "paymentType" must be one of: 0 = PayEnd, 1 = PayBegin.

func finance.PresentValue(rate float64, numPeriods int, pmt float64, fv float64, paymentType int)pv float64, err error

PresentValue returns the Present Value of a cash flow with constant payments and interest rate (annuities). Excel equivalent: PV. "paymentType" must be one of: 0 = PayEnd, 1 = PayBegin.

func finance.PriceDiscount(settlement int64, maturity int64, discount float64, redemption float64, basis int) float64

PriceDiscount returns the price per $100 face value of a discounted bond. "settlement" is the unix timestamp (seconds) for the settlement date. "maturity" is the unix timestamp (seconds) for the maturity date. "discount" is the bond's discount rate. "redemption" is the bond's redemption value per $100 face value. Excel equivalent: PRICEDISC. "basis" must be one of: 0 = US(NASD) 30/360, 1 = Actual/actual, 2 = Actual/360, 3 = Actual/365, 4 = European 30/360.

func finance.PrincipalPayment(rate float64, period int, numPeriods int, pv float64, fv float64, paymentType int) float64, error

PrincipalPayment returns the principal payment for a given period for a cash flow with constant periodic payments (annuities). Excel equivalent: PPMT. "paymentType" must be one of: 0 = PayEnd, 1 = PayBegin.

func finance.Rate(numPeriods int, pmt float64, pv float64, fv float64, paymentType int, guess float64) float64, error

Rate returns the periodic interest rate for a cash flow with constant periodic payments (annuities). Guess is a guess for the rate, used as a starting point for the iterative algorithm. Excel equivalent: RATE. "paymentType" must be one of: 0 = PayEnd, 1 = PayBegin.

func finance.TBillEquivalentYield(settlement int64, maturity int64, discount float64) float64, error

TBillEquivalentYield returns the bond-equivalent yield for a Treasury bill. "settlement" is the unix timestamp (seconds) for the settlement date. "maturity" is the unix timestamp (seconds) for the maturity date. "discount" is the T-Bill discount rate. Excel equivalent: TBILLEQ.

func finance.TBillPrice(settlement int64, maturity int64, discount float64) float64, error

TBillPrice returns the price per $100 face value for a Treasury bill. "settlement" is the unix timestamp (seconds) for the settlement date. "maturity" is the unix timestamp (seconds) for the maturity date. "discount" is the T-Bill discount rate. Excel equivalent: TBILLPRICE.

func finance.TBillYield(settlement int64, maturity int64, price float64) float64, error

TBillYield returns the yield for a treasury bill. "settlement" is the unix timestamp (seconds) for the settlement date. "maturity" is the unix timestamp (seconds) for the maturity date. "price" is the TBill price per $100 face value. Excel equivalent: TBILLYIELD.

hex

func hex.EncodeToString(src []byte) string

EncodeToString returns the hexadecimal encoding of src.

func hex.DecodeString(s string) []byte, error

DecodeString returns the bytes represented by the hexadecimal string s.

DecodeString expects that src contains only hexadecimal characters and that src has even length. If the input is malformed, DecodeString returns the bytes decoded before the error.

html

func html.EscapeString(s string) string

EscapeString escapes special characters like "<" to become "<". It escapes only five such characters: <, >, &, ' and ". UnescapeString(EscapeString(s)) == s always holds, but the converse isn't always true.

func html.UnescapeString(s string) string

UnescapeString unescapes entities like "<" to become "<". It unescapes a larger range of entities than EscapeString escapes. For example, "á" unescapes to "á", as does "á" and "á". UnescapeString(EscapeString(s)) == s always holds, but the converse isn't always true.

json

func json.Marshal(v any) []byte, error

Marshal returns the JSON encoding of v.

Marshal traverses the value v recursively. If an encountered value implements [Marshaler] and is not a nil pointer, Marshal calls [Marshaler.MarshalJSON] to produce JSON. If no [Marshaler.MarshalJSON] method is present but the value implements [encoding.TextMarshaler] instead, Marshal calls [encoding.TextMarshaler.MarshalText] and encodes the result as a JSON string. The nil pointer exception is not strictly necessary but mimics a similar, necessary exception in the behavior of [Unmarshaler.UnmarshalJSON].

Otherwise, Marshal uses the following type-dependent default encodings:

Boolean values encode as JSON booleans.

Floating point, integer, and [Number] values encode as JSON numbers. NaN and +/-Inf values will return an [UnsupportedValueError].

String values encode as JSON strings coerced to valid UTF-8, replacing invalid bytes with the Unicode replacement rune. So that the JSON will be safe to embed inside HTML tags, the string is encoded using [HTMLEscape], which replaces "<", ">", "&", U+2028, and U+2029 are escaped to "\u003c","\u003e", "\u0026", "\u2028", and "\u2029". This replacement can be disabled when using an [Encoder], by calling Encoder.SetEscapeHTML(false).

Array and slice values encode as JSON arrays, except that []byte encodes as a base64-encoded string, and a nil slice encodes as the null JSON value.

Struct values encode as JSON objects. Each exported struct field becomes a member of the object, using the field name as the object key, unless the field is omitted for one of the reasons given below.

The encoding of each struct field can be customized by the format string stored under the "json" key in the struct field's tag. The format string gives the name of the field, possibly followed by a comma-separated list of options. The name may be empty in order to specify options without overriding the default field name.

The "omitempty" option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string.

As a special case, if the field tag is "-", the field is always omitted. Note that a field with name "-" can still be generated using the tag "-,".

Examples of struct field tags and their meanings:

// Field appears in JSON as key "myName".
Field int `json:"myName"`

// Field appears in JSON as key "myName" and
// the field is omitted from the object if its value is empty,
// as defined above.
Field int `json:"myName,omitempty"`

// Field appears in JSON as key "Field" (the default), but
// the field is skipped if empty.
// Note the leading comma.
Field int `json:",omitempty"`

// Field is ignored by this package.
Field int `json:"-"`

// Field appears in JSON as key "-".
Field int `json:"-,"`

The "string" option signals that a field is stored as JSON inside a JSON-encoded string. It applies only to fields of string, floating point, integer, or boolean types. This extra level of encoding is sometimes used when communicating with JavaScript programs:

Int64String int64 `json:",string"`

The key name will be used if it's a non-empty string consisting of only Unicode letters, digits, and ASCII punctuation except quotation marks, backslash, and comma.

Embedded struct fields are usually marshaled as if their inner exported fields were fields in the outer struct, subject to the usual Go visibility rules amended as described in the next paragraph. An anonymous struct field with a name given in its JSON tag is treated as having that name, rather than being anonymous. An anonymous struct field of interface type is treated the same as having that type as its name, rather than being anonymous.

The Go visibility rules for struct fields are amended for JSON when deciding which field to marshal or unmarshal. If there are multiple fields at the same level, and that level is the least nested (and would therefore be the nesting level selected by the usual Go rules), the following extra rules apply:

  1. Of those fields, if any are JSON-tagged, only tagged fields are considered, even if there are multiple untagged fields that would otherwise conflict.

  2. If there is exactly one field (tagged or not according to the first rule), that is selected.

  3. Otherwise there are multiple fields, and all are ignored; no error occurs.

Handling of anonymous struct fields is new in Go 1.1. Prior to Go 1.1, anonymous struct fields were ignored. To force ignoring of an anonymous struct field in both current and earlier versions, give the field a JSON tag of "-".

Map values encode as JSON objects. The map's key type must either be a string, an integer type, or implement [encoding.TextMarshaler]. The map keys are sorted and used as JSON object keys by applying the following rules, subject to the UTF-8 coercion described for string values above:

  • keys of any string type are used directly
  • [encoding.TextMarshalers] are marshaled
  • integer keys are converted to strings

Pointer values encode as the value pointed to. A nil pointer encodes as the null JSON value.

Interface values encode as the value contained in the interface. A nil interface value encodes as the null JSON value.

Channel, complex, and function values cannot be encoded in JSON. Attempting to encode such a value causes Marshal to return an [UnsupportedTypeError].

JSON cannot represent cyclic data structures and Marshal does not handle them. Passing cyclic structures to Marshal will result in an error.

math

func math.Abs(x float64) float64

Abs returns the absolute value of x.

Special cases are:

Abs(±Inf) = +Inf
Abs(NaN) = NaN

func math.Cbrt(x float64) float64

Cbrt returns the cube root of x.

Special cases are:

Cbrt(±0) = ±0
Cbrt(±Inf) = ±Inf
Cbrt(NaN) = NaN

func math.Copysign(f float64, sign float64) float64

Copysign returns a value with the magnitude of f and the sign of sign.

func math.Dim(x float64, y float64) float64

Dim returns the maximum of x-y or 0.

Special cases are:

Dim(+Inf, +Inf) = NaN
Dim(-Inf, -Inf) = NaN
Dim(x, NaN) = Dim(NaN, x) = NaN

func math.Max(x float64, y float64) float64

Max returns the larger of x or y.

Special cases are:

Max(x, +Inf) = Max(+Inf, x) = +Inf
Max(x, NaN) = Max(NaN, x) = NaN
Max(+0, ±0) = Max(±0, +0) = +0
Max(-0, -0) = -0

Note that this differs from the built-in function max when called with NaN and +Inf.

func math.Min(x float64, y float64) float64

Min returns the smaller of x or y.

Special cases are:

Min(x, -Inf) = Min(-Inf, x) = -Inf
Min(x, NaN) = Min(NaN, x) = NaN
Min(-0, ±0) = Min(±0, -0) = -0

Note that this differs from the built-in function min when called with NaN and -Inf.

func math.Exp(x float64) float64

Exp returns e**x, the base-e exponential of x.

Special cases are:

Exp(+Inf) = +Inf
Exp(NaN) = NaN

Very large values overflow to 0 or +Inf. Very small values underflow to 1.

func math.Exp2(x float64) float64

Exp2 returns 2**x, the base-2 exponential of x.

Special cases are the same as [Exp].

func math.Expm1(x float64) float64

Expm1 returns e**x - 1, the base-e exponential of x minus 1. It is more accurate than Exp(x) - 1 when x is near zero.

Special cases are:

Expm1(+Inf) = +Inf
Expm1(-Inf) = -1
Expm1(NaN) = NaN

Very large values overflow to -1 or +Inf.

func math.Floor(x float64) float64

Floor returns the greatest integer value less than or equal to x.

Special cases are:

Floor(±0) = ±0
Floor(±Inf) = ±Inf
Floor(NaN) = NaN

func math.Ceil(x float64) float64

Ceil returns the least integer value greater than or equal to x.

Special cases are:

Ceil(±0) = ±0
Ceil(±Inf) = ±Inf
Ceil(NaN) = NaN

func math.Trunc(x float64) float64

Trunc returns the integer value of x.

Special cases are:

Trunc(±0) = ±0
Trunc(±Inf) = ±Inf
Trunc(NaN) = NaN

func math.Round(x float64) float64

Round returns the nearest integer, rounding half away from zero.

Special cases are:

Round(±0) = ±0
Round(±Inf) = ±Inf
Round(NaN) = NaN

func math.RoundToEven(x float64) float64

RoundToEven returns the nearest integer, rounding ties to even.

Special cases are:

RoundToEven(±0) = ±0
RoundToEven(±Inf) = ±Inf
RoundToEven(NaN) = NaN

func math.FMA(x float64, y float64, z float64) float64

FMA returns x * y + z, computed with only one rounding. (That is, FMA returns the fused multiply-add of x, y, and z.)

func math.Hypot(p float64, q float64) float64

Hypot returns [Sqrt](pp + qq), taking care to avoid unnecessary overflow and underflow.

Special cases are:

Hypot(±Inf, q) = +Inf
Hypot(p, ±Inf) = +Inf
Hypot(NaN, q) = NaN
Hypot(p, NaN) = NaN

func math.Log(x float64) float64

Log returns the natural logarithm of x.

Special cases are:

Log(+Inf) = +Inf
Log(0) = -Inf
Log(x < 0) = NaN
Log(NaN) = NaN

func math.Log10(x float64) float64

Log10 returns the decimal logarithm of x. The special cases are the same as for [Log].

func math.Log2(x float64) float64

Log2 returns the binary logarithm of x. The special cases are the same as for [Log].

func math.Log1p(x float64) float64

Log1p returns the natural logarithm of 1 plus its argument x. It is more accurate than [Log](1 + x) when x is near zero.

Special cases are:

Log1p(+Inf) = +Inf
Log1p(±0) = ±0
Log1p(-1) = -Inf
Log1p(x < -1) = NaN
Log1p(NaN) = NaN

func math.Mod(x float64, y float64) float64

Mod returns the floating-point remainder of x/y. The magnitude of the result is less than y and its sign agrees with that of x.

Special cases are:

Mod(±Inf, y) = NaN
Mod(NaN, y) = NaN
Mod(x, 0) = NaN
Mod(x, ±Inf) = x
Mod(x, NaN) = NaN

func math.Pow(x float64, y float64) float64

Pow returns x**y, the base-x exponential of y.

Special cases are (in order):

Pow(x, ±0) = 1 for any x
Pow(1, y) = 1 for any y
Pow(x, 1) = x for any x
Pow(NaN, y) = NaN
Pow(x, NaN) = NaN
Pow(±0, y) = ±Inf for y an odd integer < 0
Pow(±0, -Inf) = +Inf
Pow(±0, +Inf) = +0
Pow(±0, y) = +Inf for finite y < 0 and not an odd integer
Pow(±0, y) = ±0 for y an odd integer > 0
Pow(±0, y) = +0 for finite y > 0 and not an odd integer
Pow(-1, ±Inf) = 1
Pow(x, +Inf) = +Inf for |x| > 1
Pow(x, -Inf) = +0 for |x| > 1
Pow(x, +Inf) = +0 for |x| < 1
Pow(x, -Inf) = +Inf for |x| < 1
Pow(+Inf, y) = +Inf for y > 0
Pow(+Inf, y) = +0 for y < 0
Pow(-Inf, y) = Pow(-0, -y)
Pow(x, y) = NaN for finite x < 0 and finite non-integer y

func math.Pow10(n int) float64

Pow10 returns 10**n, the base-10 exponential of n.

Special cases are:

Pow10(n) =    0 for n < -323
Pow10(n) = +Inf for n > 308

func math.Remainder(x float64, y float64) float64

Remainder returns the IEEE 754 floating-point remainder of x/y.

Special cases are:

Remainder(±Inf, y) = NaN
Remainder(NaN, y) = NaN
Remainder(x, 0) = NaN
Remainder(x, ±Inf) = x
Remainder(x, NaN) = NaN

func math.Signbit(x float64) bool

Signbit reports whether x is negative or negative zero.

func math.Sqrt(x float64) float64

Sqrt returns the square root of x.

Special cases are:

Sqrt(+Inf) = +Inf
Sqrt(±0) = ±0
Sqrt(x < 0) = NaN
Sqrt(NaN) = NaN

md5

func md5.Sum(data []byte) []byte

Sum returns the MD5 checksum of the data.

money

func money.Add(a money, b money) money, error

Add two Money types and return the result

func money.Sub(a money, b money) money, error

Compute the difference between two Money types

func money.Mul(a money, b string) money, error

Multiply a Money type by a string-represented number

func money.Div(a money, b string) money, error

Divide a Money type by a string-represented number

path

func path.Clean(path string) string

Clean returns the shortest path name equivalent to path by purely lexical processing. It applies the following rules iteratively until no further processing can be done:

  1. Replace multiple slashes with a single slash.
  2. Eliminate each . path name element (the current directory).
  3. Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
  4. Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path.

The returned path ends in a slash only if it is the root "/".

If the result of this process is an empty string, Clean returns the string ".".

See also Rob Pike, “Lexical File Names in Plan 9 or Getting Dot-Dot Right,” https://9p.io/sys/doc/lexnames.html

func path.Ext(path string) string

Ext returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final slash-separated element of path; it is empty if there is no dot.

func path.Base(path string) string

Base returns the last element of path. Trailing slashes are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of slashes, Base returns "/".

func path.IsAbs(path string) bool

IsAbs reports whether the path is absolute.

func path.Dir(path string) string

Dir returns all but the last element of path, typically the path's directory. After dropping the final element using [Split], the path is Cleaned and trailing slashes are removed. If the path is empty, Dir returns ".". If the path consists entirely of slashes followed by non-slash bytes, Dir returns a single slash. In any other case, the returned path does not end in a slash.

rand

func rand.Int63() int64

Int63 returns a non-negative pseudo-random 63-bit integer as an int64 from the default [Source].

func rand.Uint32() uint32

Uint32 returns a pseudo-random 32-bit value as a uint32 from the default [Source].

func rand.Uint64() uint64

Uint64 returns a pseudo-random 64-bit value as a uint64 from the default [Source].

func rand.Int31() int32

Int31 returns a non-negative pseudo-random 31-bit integer as an int32 from the default [Source].

func rand.Int() int

Int returns a non-negative pseudo-random int from the default [Source].

func rand.Int63n(n int64) int64

Int63n returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n) from the default [Source]. It panics if n <= 0.

func rand.Int31n(n int32) int32

Int31n returns, as an int32, a non-negative pseudo-random number in the half-open interval [0,n) from the default [Source]. It panics if n <= 0.

func rand.Intn(n int) int

Intn returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n) from the default [Source]. It panics if n <= 0.

func rand.Float64() float64

Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0) from the default [Source].

func rand.Float32() float32

Float32 returns, as a float32, a pseudo-random number in the half-open interval [0.0,1.0) from the default [Source].

func rand.NormFloat64() float64

NormFloat64 returns a normally distributed float64 in the range [-[math.MaxFloat64], +[math.MaxFloat64]] with standard normal distribution (mean = 0, stddev = 1) from the default [Source]. To produce a different normal distribution, callers can adjust the output using:

sample = NormFloat64() * desiredStdDev + desiredMean

func rand.ExpFloat64() float64

ExpFloat64 returns an exponentially distributed float64 in the range (0, +[math.MaxFloat64]] with an exponential distribution whose rate parameter (lambda) is 1 and whose mean is 1/lambda (1) from the default [Source]. To produce a distribution with a different rate parameter, callers can adjust the output using:

sample = ExpFloat64() / desiredRateParameter

sha1

func sha1.Sum(data []byte) []byte

Sum returns the SHA-1 checksum of the data.

sha256

func sha256.Sum256(data []byte) []byte

Sum256 returns the SHA256 checksum of the data.

sha512

func sha512.Sum512(data []byte) []byte

Sum512 returns the SHA512 checksum of the data.

strings

func strings.Compare(a string, b string) int

Compare returns an integer comparing two strings lexicographically. The result will be 0 if a == b, -1 if a < b, and +1 if a > b.

Compare is included only for symmetry with package bytes. It is usually clearer and always faster to use the built-in string comparison operators ==, <, >, and so on.

func strings.Count(s string, substr string) int

Count counts the number of non-overlapping instances of substr in s. If substr is an empty string, Count returns 1 + the number of Unicode code points in s.

func strings.Contains(s string, substr string) bool

Contains reports whether substr is within s.

func strings.ContainsAny(s string, chars string) bool

ContainsAny reports whether any Unicode code points in chars are within s.

func strings.LastIndex(s string, substr string) int

LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.

func strings.IndexAny(s string, chars string) int

IndexAny returns the index of the first instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.

func strings.LastIndexAny(s string, chars string) int

LastIndexAny returns the index of the last instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.

func strings.HasPrefix(s string, prefix string) bool

HasPrefix reports whether the string s begins with prefix.

func strings.HasSuffix(s string, suffix string) bool

HasSuffix reports whether the string s ends with suffix.

func strings.Repeat(s string, count int) string

Repeat returns a new string consisting of count copies of the string s.

It panics if count is negative or if the result of (len(s) * count) overflows.

func strings.ToUpper(s string) string

ToUpper returns s with all Unicode letters mapped to their upper case.

func strings.ToLower(s string) string

ToLower returns s with all Unicode letters mapped to their lower case.

func strings.ToTitle(s string) string

ToTitle returns a copy of the string s with all Unicode letters mapped to their Unicode title case.

func strings.ToValidUTF8(s string, replacement string) string

ToValidUTF8 returns a copy of the string s with each run of invalid UTF-8 byte sequences replaced by the replacement string, which may be empty.

func strings.Title(s string) string

Title returns a copy of the string s with all Unicode letters that begin words mapped to their Unicode title case.

Deprecated: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead.

func strings.Trim(s string, cutset string) string

Trim returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.

func strings.TrimLeft(s string, cutset string) string

TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.

To remove a prefix, use [TrimPrefix] instead.

func strings.TrimRight(s string, cutset string) string

TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.

To remove a suffix, use [TrimSuffix] instead.

func strings.TrimSpace(s string) string

TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.

func strings.TrimPrefix(s string, prefix string) string

TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.

func strings.TrimSuffix(s string, suffix string) string

TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.

func strings.Replace(s string, old string, new string, n int) string

Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. If n < 0, there is no limit on the number of replacements.

func strings.ReplaceAll(s string, old string, new string) string

ReplaceAll returns a copy of the string s with all non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string.

func strings.EqualFold(s string, t string) bool

EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under simple Unicode case-folding, which is a more general form of case-insensitivity.

func strings.Index(s string, substr string) int

Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.

url

func url.QueryEscape(s string) string

QueryEscape escapes the string so it can be safely placed inside a [URL] query.

func url.PathEscape(s string) string

PathEscape escapes the string so it can be safely placed inside a [URL] path segment, replacing special characters (including /) with %XX sequences as needed.

uuid

func uuid.New() uuid

New creates a new random UUID.

func uuid.NewMD5(space uuid, data []byte) uuid

NewMD5 returns a new MD5 (Version 3) UUID based on the supplied name space and data.

func uuid.NewSHA1(space uuid, data []byte) uuid

NewSHA1 returns a new SHA1 (Version 5) UUID based on the supplied name space and data.