getFullRandom

说明

获取指定范围内的随机整数

源码

用法

getFullRandom.test.ts
1
import { getFullRandom } from "../../utility/number/getFullRandom";
2
3
describe('getFullRandom', () => {
4
test('getFullRandom should receive two numbers and return a interger between these two numbers', () => {
5
const origin = [
6
{
7
min: 0,
8
max: 10,
9
},
10
{
11
min: Number.MIN_SAFE_INTEGER,
12
max: Number.MAX_SAFE_INTEGER,
13
},
14
{
15
min: -1,
16
max: 1,
17
}
18
];
19
20
for (const v of origin) {
21
const { min, max } = v;
22
23
const result = getFullRandom(
24
min,
25
max,
26
);
27
28
expect(Number.isInteger(result)).toBeTruthy();
29
expect(result >= min && result <= max).toBeTruthy();
30
}
31
});
32
});
Copied!
最近更新 1yr ago
复制链接