1 | import Long from 'long'
|
2 |
|
3 | export default class RandomIntGenerator {
|
4 | // static generate () {
|
5 | // return Math.floor(Math.random() * (Math.pow(2, 32) + 1))
|
6 | // }
|
7 | static getAttemptId (): Long {
|
8 | const sysTime: Long = Long.fromNumber(Date.now()).shiftLeft(22)
|
9 | const randomBit: Long = Long.fromNumber(RandomIntGenerator.generate() & 4194303).and(Long.MAX_VALUE)
|
10 | return sysTime.or(randomBit)
|
11 | }
|
12 |
|
13 | static generate () {
|
14 | return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER))
|
15 | }
|
16 | }
|