我试图创建一个随机的32字节缓冲区,以下是我的代码(尚未起作用):
let buf = Buffer.alloc(32).fill(0)
console.log('Buffer: ',buf)
buf.writeUInt16BE(Math.floor(Math.random() * 2147483647).toString(16),5)
console.log('Random Buffer: ',buf)
有人知道一个好的方法来做这件事吗?
value
的值不为一个16位无符号整数时,行为是未定义的。你正在传递一个字符串作为value
参数。 - jonrsharpe