trerandom.js是一个实用程序JS库,使用量子随机性提供真正的随机数。
限制:
truerandom.js需要node.js v4+运行。
安装模块。
npm i truerandom.js如何在项目中使用trerandom.js的一个示例。
const tr = require( ' truerandom.js ' ) ;
//Generating 2 unint16 numbers
tr.generate( ' uint16 ' ,2)
.then(response = > {
//Do whatever with your generated numbers
console.log(response+ ' -generated 2 uint16 numbers and then joined together ' ) ;
})
.catch(error = > {
// handle error here
}) ;
//Generating ' n ' digits of random numbers
tr.digits(20)
.then(response = > {
console.log(response+ ' -generated 20 digit random number ' ) ;
})
.catch(error = > {
// handle error here
}) ;
目前有2个功能可供使用:
用于生成一个随机数的“类型”的“ n”数。结果是“承诺”。因此,您必须使用“。然后”捕获错误正确处理。
示例代码:
tr.generate('uint16',2)
.then(response => {
//Do whatever with your generated numbers
})
.catch(error => {
// handle error here
});
生成功能采用3个参数
生成功能支持3种数字类型
ANU(澳大利亚国立大学)最初发送您选择的“数字类型”(即UINT8,UINT16或HEX16)。 “数字”参数实际上是总数。您想要在数组中的数字。然后truerandom.js然后加入该数组,并为您提供一个数字字符串。
例如 - 如果您使用以下代码:
tr.generate('uint8',2)
.then(response => {
//Do whatever with your generated numbers
})
.catch(error => {
// handle error here
});
然后trerandom.js收到的原始响应是
[219,172]
然后,truerandom.js然后进一步加入数组,并返回一个类似的字符串 -
219172
因此,数字参数实际上是所请求的数组的长度,该长度与NO直接成正比。生成的随机数的数字。
从广义上讲,更大的否。您在数字参数中使用较大的随机数将生成更大的随机数
您可以在数字参数中使用的最大数字为1024。因此,数字参数必须范围为1-1024
仅在请求HEX16类型的数字时才需要此参数。这是每个数组中您需要的Hex16数字的一半。例如 -
tr.generate('hex16',1,10)
.then(response => {
//Do whatever with your generated numbers
})
.catch(error => {
// handle error here
});
会返回
fc3eebbbf3f6abade4b1 // size is 20 which is double the given length
尽管
tr.generate('hex16',1,25)
.then(response => {
//Do whatever with your generated numbers
})
.catch(error => {
// handle error here
});
会返回
8665c4c7a9db220c483136a701c51a1f797bc5ae69a5de75de // size is 50 which is double the given length
用于生成随机数的“ n”数字。结果是“承诺”。因此,您必须使用“。然后”捕获错误正确处理。
示例代码:
tr.digits(20)
.then(response => {
//Do whatever with your generated numbers gives also the number of digits is 2
})
.catch(error => {
// handle error here
});
数字函数仅采用一个参数
这是预期数字的数量不能超过5124
用于生成盐的MD5。结果是“承诺”。因此,您必须使用“。然后”捕获错误正确处理。
示例代码:
tr.md5("Hi Bob",20)
.then(response => {
//Returns an array of 2 items. First is the md5 hash of the message and the second is the salt used
})
.catch(error => {
// handle error here
});
响应是2个项目的数组
数字功能采用2个参数
散布的消息。预期字符串。
哈希数字的长度要使用。不能超过5124
用于生成盐的SHA1。结果是“承诺”。因此,您必须使用“。然后”捕获错误正确处理。
示例代码:
tr.sha1("Hi Bob",20)
.then(response => {
//Returns an array of 2 items. First is the sha1 hash of the message and the second is the salt used
})
.catch(error => {
// handle error here
});
响应是2个项目的数组
数字功能采用2个参数
散布的消息。预期字符串。
哈希数字的长度要使用。不能超过5124
用于生成盐的双重货币。结果是“承诺”。因此,您必须使用“。然后”捕获错误正确处理。
示例代码:
tr.doubleHash("Hi Bob",20)
.then(response => {
//Returns an array of 2 items. First is the doubleHash hash of the message and the second is the salt used
})
.catch(error => {
// handle error here
});
响应是2个项目的数组
数字功能采用2个参数
散布的消息。预期字符串。
哈希数字的长度要使用。不能超过5124
用于生成盐的SHA256。结果是“承诺”。因此,您必须使用“。然后”捕获错误正确处理。
示例代码:
tr.sha256("Hi Bob",20)
.then(response => {
//Returns an array of 2 items. First is the sha256 hash of the message and the second is the salt used
})
.catch(error => {
// handle error here
});
响应是2个项目的数组
数字功能采用2个参数
散布的消息。预期字符串。
哈希数字的长度要使用。预计数量不能超过5124
该项目需要贡献,如果您愿意支持此项目,请不要害怕留言或提出拉请。质量更改需要在文档中进行,并进行功能添加和测试。我还鼓励您分享您的项目,如果您在项目中使用此模块,我很乐意在这里展示它们。
麻省理工学院