[nodeJS] generate signed random numbers via random.org

Costas

Administrator
Staff member
references :

https://api.random.org/json-rpc/2/introduction

https://api.random.org/json-rpc/2/

<a href="https://api.random.org/json-rpc/2/error-codes">https://api.random.org/json-rpc/2/error-codes
</a>

alternative libs ready to use for nodeJS :

https://npmjs.org/package/node-random or https://github.com/mikeal/request

https://github.com/Epictetus/random-proxy

 

get beta key at https://api.random.org/api-keys/beta

1-

install request library at nodeJS via https://npmjs.org/package/request

JavaScript:
npm install request

2-

use this code to generate signed numbers :

JavaScript:
var request = require('request');
request({
	method : 'PUT',
	uri : 'https://api.random.org/json-rpc/1/invoke',
	headers : {
		'content-type' : 'application/json-rpc'
	},
	body : JSON.stringify({
		"jsonrpc" : "2.0",
		"method" : "generateSignedIntegers",
		"params" : {
			"apiKey" : "your beta API key",
			"n" : 6,
			"min" : 1,
			"max" : 6,
			"replacement" : true,
			"base" : 10
		},
		"id" : 14215 //without this variable you will never get valid response
		             //A request identifier that allows the client to match responses to request. The service will return this unchanged in its response.
	})
}, function(error, response, body) {
        var info = JSON.parse(body);
	//console.log(response.statusCode, body);
        console.log(info.result.random.data);
})

is NOT free, from first run on response you will see

JavaScript:
"bitsUsed":16,"bitsLeft":249904,"requestsLeft":994

yes pay them by bits or by requests!

ps you can also without APIkey via
JavaScript:
http://www.random.org/integers/?num=1&min=1&max=6&col=1&base=10&format=plain&rnd=new
again restrictions applied.
 
Top