import { randomBytes } from "crypto" ; import { jspack } from "jspack" ; export function random16 ( ) { return jspack . Unpack ( "!H" , randomBytes ( 2 ) ) [ 0 ] ; } export function random32 ( ) { return BigInt ( jspack . Unpack ( "!L" , randomBytes ( 4 ) ) [ 0 ] ) ; } export function uint16Add ( a , b ) { return ( a + b ) & 0xffff ; } export function uint32_add ( a , b ) { return ( a + b ) & 0xffffffffn ; } export function uint16Gt ( a , b ) { const halfMod = 0x8000 ; return ( a < b && b - a > halfMod ) || ( a > b && a - b < halfMod ) ; } export function uint16Gte ( a , b ) { return a === b || uint16Gt ( a , b ) ; } export function uint32Gt ( a , b ) { const halfMod = 0x80000000 ; return ( a < b && b - a > halfMod ) || ( a > b && a - b < halfMod ) ; } export function uint32Gte ( a , b ) { return a === b || uint32Gt ( a , b ) ; }