Truerandom.js는 양자 무작위성을 사용하여 진정한 랜덤 숫자를 제공하는 유틸리티 노드 JS 라이브러리입니다.
제한 사항 :
truerandom.js는 node.js v4+가 실행되기 위해 필요합니다.
모듈 설치.
npm i truerandom.js프로젝트에서 truerandom.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
}) ;
현재 사용 가능한 두 가지 기능이 있습니다.
임의의 '유형'의 'n'수를 생성하는 데 사용됩니다. 결과는 '약속'입니다. 따라서 '.then'을 사용하여 올바르게 처리하고 오류를 잡아야합니다.
예제 코드 :
tr.generate('uint16',2)
.then(response => {
//Do whatever with your generated numbers
})
.catch(error => {
// handle error here
});
생성 함수는 3 개의 매개 변수를 가져옵니다
생성 기능은 3 가지 유형의 숫자를 지원합니다
Anu (Australian National University)는 원래 선택한 '유형'배열을 보냅니다 (예 : UINT8, UINT16 또는 HEX16). '번호'매개 변수는 실제로 총 번호입니다. 배열에서 원하는 숫자. Truerandom.js는 해당 배열에 합류하여 숫자 문자열을 제공합니다.
예를 들어 다음 코드를 사용하는 경우 :
tr.generate('uint8',2)
.then(response => {
//Do whatever with your generated numbers
})
.catch(error => {
// handle error here
});
그런 다음 Truerandom.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'숫자를 생성하는 데 사용됩니다. 결과는 '약속'입니다. 따라서 '.then'을 사용하여 올바르게 처리하고 오류를 잡아야합니다.
예제 코드 :
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를 생성하는 데 사용됩니다. 결과는 '약속'입니다. 따라서 '.then'을 사용하여 올바르게 처리하고 오류를 잡아야합니다.
예제 코드 :
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을 생성하는 데 사용됩니다. 결과는 '약속'입니다. 따라서 '.then'을 사용하여 올바르게 처리하고 오류를 잡아야합니다.
예제 코드 :
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 이상을 초과 할 수 없습니다
소금에 절인 더블 하쉬를 생성하는 데 사용됩니다. 결과는 '약속'입니다. 따라서 '.then'을 사용하여 올바르게 처리하고 오류를 잡아야합니다.
예제 코드 :
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을 생성하는 데 사용됩니다. 결과는 '약속'입니다. 따라서 '.then'을 사용하여 올바르게 처리하고 오류를 잡아야합니다.
예제 코드 :
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 이상을 초과 할 수 없습니다
이 프로젝트에는 기여가 필요합니다.이 프로젝트를 기꺼이 지원하려면 메시지를 남기거나 풀 요청을 두려워하지 마십시오. 기능 추가 및 테스트와 함께 문서에서 품질 변경을 수행해야합니다. 또한 프로젝트 에서이 모듈을 사용하는 경우 프로젝트를 공유하는 것이 좋습니다.
MIT