TrueRandom.js is an utility node js library which provides truly random numbers using quantum randomness.
Limitations:
TrueRandom.js requires Node.js v4+ to run.
Installing the module .
npm i truerandom.jsAn example of how to use TrueRandom.js in your projects.
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
});
Currently there are 2 functions available to use:
Used to generate 'n' number of a 'type' of random number. The result is a 'promise'. So u must handle it properly using '.then' and catch errors.
Example code:
tr.generate('uint16',2)
.then(response => {
//Do whatever with your generated numbers
})
.catch(error => {
// handle error here
});
the generate function takes 3 parameters
The generate function supports 3 type of numbers
Anu (Australian national university) originally sends an array of the 'type' of number you chose(i.e - either uint8,uint16 or hex16). The 'number' parameter is actually the total no. of numbers you want in an array. TrueRandom.js then joins that array and gives you an string of number.
For example- if you use the following code:
tr.generate('uint8',2)
.then(response => {
//Do whatever with your generated numbers
})
.catch(error => {
// handle error here
});
Then the original response received by TrueRandom.js is
[219,172]
TrueRandom.js then further joins the array and returns a string similar to-
219172
Hence the number parameter is actually the length of the array requested which is directly proportional to the no. of digits of the random number generated.
Broadly speaking the bigger no. you use in the number parameter the bigger random number will be generated
The maximum number you can use in the number parameter is 1024. Hence the number parameter must range from 1–1024
This parameter is only necessary when requesting hex16 type of numbers. It is the half length of the hex16 number u need in each array. for example -
tr.generate('hex16',1,10)
.then(response => {
//Do whatever with your generated numbers
})
.catch(error => {
// handle error here
});
will return
fc3eebbbf3f6abade4b1 // size is 20 which is double the given length
while
tr.generate('hex16',1,25)
.then(response => {
//Do whatever with your generated numbers
})
.catch(error => {
// handle error here
});
will return
8665c4c7a9db220c483136a701c51a1f797bc5ae69a5de75de // size is 50 which is double the given length
Used to generate 'n' digits of random numbers. The result is a ‘promise’. So u must handle it properly using ‘.then’ and catch errors.
Example code:
tr.digits(20)
.then(response => {
//Do whatever with your generated numbers gives also the number of digits is 2
})
.catch(error => {
// handle error here
});
the digits function takes only one parameter
This is the number of digits expected Cannot exceed more than 5124
Used to generate a salted md5. The result is a ‘promise’. So u must handle it properly using ‘.then’ and catch errors.
Example code:
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
});
the response is an array of 2 items
the digits function takes 2 parameter
Message to be hashed. Expected string.
length of the digits of hash to be used. Cannot exceed more than 5124
Used to generate a salted sha1. The result is a ‘promise’. So u must handle it properly using ‘.then’ and catch errors.
Example code:
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
});
the response is an array of 2 items
the digits function takes 2 parameter
Message to be hashed. Expected string.
length of the digits of hash to be used. Cannot exceed more than 5124
Used to generate a salted doubleHash. The result is a ‘promise’. So u must handle it properly using ‘.then’ and catch errors.
Example code:
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
});
the response is an array of 2 items
the digits function takes 2 parameter
Message to be hashed. Expected string.
length of the digits of hash to be used. Cannot exceed more than 5124
Used to generate a salted sha256. The result is a ‘promise’. So u must handle it properly using ‘.then’ and catch errors.
Example code:
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
});
the response is an array of 2 items
the digits function takes 2 parameter
Message to be hashed. Expected string.
length of the digits of hash to be used. expeted number Cannot exceed more than 5124
This project requires contribution, if you are willing to support this project please don't be afraid to leave a message or make a pull request. Quality changes needs to be done in the documentation along with feature addition and testing. I also encourage you to share your projects if you use this module in your projects I would be more than happy to feature them here.
MIT