Mock.Random.boolean( min?, max?, current? ), Returns a random Boolean value.
- Min: indicates the probability of occurrence of the parameter current. The probability calculation formula is min / (min + max). The default value of this parameter is 1, that is, there is a 50% probability of returning the parameter current.
- Max: indicates the opposite value of the parameter current! Probability of current occurrence. The probability calculation formula is max / (min + max). The default value of this parameter is 1, that is, there is a 50% probability of returning the parameter! current.
- current: the optional values are Boolean true or false. If no parameters are passed in, the probability of returning true and false is 50% respectively. This parameter has no default value. Inside this method, according to the native method math The (floating-point) number returned by random() is used to calculate and return Boolean values. For example, in the simplest case, the return value is the expression math Execution result of random() > = 0.5.
Mock.Random.boolean() // true Mock.Random.boolean(1, 9, true) // false
Mock.Random.natural( min?, max? ), Returns a random natural number (an integer greater than or equal to 0).
- min: indicates the minimum value of random natural number. The default value is 0.
- max: indicates the maximum value of a random natural number. The default value is 9007199254740992.
Mock.Random.natural() // 7156385837156388 Mock.Random.natural(10000) // 6157603142411466 Mock.Random.natural(60, 100) // 82
Mock.Random.integer( min?, max? ), Returns a random integer.
- min: indicates the minimum value of a random integer. The default value is - 9007199254740992.
- max: indicates the maximum value of a random integer. The default value is 9007199254740992.
Mock.Random.integer() // -1106364738145072 Mock.Random.integer(10000) // 3825689078558115 Mock.Random.integer(-100, 0) // -61
Mock.Random.float( min?, max?, dmin?, dmax? ), Returns a random floating-point number.
- min: the minimum value of the integer part. The default value is - 9007199254740992.
- max: the maximum value of the integer part. The default value is 9007199254740992.
- dmin: the minimum number of decimal places. The default value is 0.
- dmax: maximum number of decimal places. The default value is 17.
Mock.Random.float() // 6401794162025181 Mock.Random.float(1) // 4677528980652239 Mock.Random.float(1, 100) // 85.7853461508 Mock.Random.float(1, 100, 3) // 40.89558247552 Mock.Random.float(1, 100, 3, 6) // 9.01155
Mock.Random.character( pool? ), Returns a random character.
Pool: string. Means to select a character from the character pool and return.
Mock.Random.character() // L Mock.Random.character('lower') // y Mock.Random.character('upper') // C Mock.Random.character('number') // 0 Mock.Random.character('symbol') // *
Mock.Random.string( pool?, min?, max? ), Returns a random string.
- Pool: string. Means to select a character from the character pool and return.
- min: minimum length of random string. The default value is 3.
- max: the maximum length of a random string. The default value is 7.
Mock.Random.string() // yvlO Mock.Random.string('lower', 6) // ktzuct Mock.Random.string('upper', 6) // ABTXDS Mock.Random.string('number', 6) // 648916 Mock.Random.string('symbol', 6) // *(@*%# Mock.Random.string('lower', 6, 16) // rgnwqpdvoccaguqs Mock.Random.string('upper', 6, 16) // WFATKESHXHON Mock.Random.string('number', 6, 16) // 479830634 Mock.Random.string('symbol', 6, 16) // (&@&)&)
Mock.Random.range(start?, stop, step?), Returns an integer array.
- start: the starting value of an integer in the array.
- stop: the end value of an integer in the array (not included in the return value).
- Step: the step between integers in the array. The default value is 1.
Mock.Random.range(10) // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Mock.Random.range(3, 7) // [3, 4, 5, 6] Mock.Random.range(1, 10, 2) // [1, 3, 5, 7, 9] Mock.Random.range(1, 100, 5) // [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86, 91, 96]