getAnyRandom

说明

获取指定范围内的随机自然数

源码

用法

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