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
該項目需要貢獻,如果您願意支持此項目,請不要害怕留言或提出拉請。質量更改需要在文檔中進行,並進行功能添加和測試。我還鼓勵您分享您的項目,如果您在項目中使用此模塊,我很樂意在這裡展示它們。
麻省理工學院