Documentation
¶
Index ¶
- func AbsInt8(n int8) int8
- func AbsInt16(n int16) int16
- func AbsInt32(n int32) int32
- func AbsInt64(n int64) int64
- func Max[T cmp.Ordered](x, y T) T
- func Min[T cmp.Ordered](x, y T) T
- func RandAlphanumeric(l int) string
- func RandBytes(l uint32) []byte
- func RandInt() int
- func RandIntRange(min, max int) int
- func RandIntn(n int) int
- func RandInts(l, max int) []int
- func RandLowerAlphanumeric(l int) string
- func RandLowerStr(l uint32) string
- func RandStr(l int) string
- func RandUpperStr(l uint32) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbsInt8 ¶
AbsInt8 gets absolute value of int8.
Example 1: AbsInt8(-5) -5 code value as below original code 1000,0101 inverse code 1111,1010 complement code 1111,1011 Negative numbers are represented by complement code in memory. shifted = n >> 7 = (1111,1011) >> 7 = 1111,1111 = -1(10-base) (负数右移,左补1)
1111,1011
n xor shifted = ----------- = 0000,0100 = 4(10-base)
1111,1111
(n ^ shifted) - shifted = 4 - (-1) = 5
Example 2: AbsInt8(5) 5 code value as below original code 0000,0101 Positive numbers are represented by original code in memory, and the XOR operation between positive numbers and 0 is equal to itself. shifted = n >> 7 = 0
0000,0101
n xor shifted = ----------- = 0000,0101 = 5(10-base)
0000,0000
(n ^ shifted) - shifted = 5 - 0 = 5
func Max ¶ added in v0.0.62
Max compare two values and return larger value. Deprecated: as of go 1.21, please use builtin func max.
func Min ¶ added in v0.0.62
Min compare two values and return smaller value. Deprecated: as of go 1.21, please use builtin func min.
func RandAlphanumeric ¶ added in v0.0.52
RandAlphanumeric returns a truly random string of the specified length and the contents of which are composed of alphanumeric letters.
func RandBytes ¶ added in v0.0.52
RandBytes gets a truly random byte slice of the specified length with the value range in [0x00,0xff].
func RandIntRange ¶
RandIntRange returns a non-negative truly random int number in [min,max).
func RandInts ¶ added in v0.0.52
RandInts returns a non-negative truly random int specified length slice with the value range in [0,max).
func RandLowerAlphanumeric ¶ added in v0.0.53
RandLowerAlphanumeric returns a truly random string of the specified length and the contents of which are composed of lowercase letters and numbers.
func RandLowerStr ¶
RandLowerStr returns a truly random lowercase string of a specified length.
func RandStr ¶
RandStr returns a truly random string of the specified length and the contents of which are composed of uppercase and lowercase letters.
func RandUpperStr ¶
RandUpperStr returns a truly random uppercase string of a specified length.
Types ¶
This section is empty.