random number
This commit is contained in:
31
api.php
31
api.php
@@ -482,6 +482,37 @@ elseif($q=="getTransactions"){
|
||||
$res=$db->single("SELECT COUNT(1) FROM mempool");
|
||||
api_echo($res);
|
||||
|
||||
} elseif($q=='randomNumber'){
|
||||
/**
|
||||
* @api {get} /api.php?q=randomNumber 16. randomNumber
|
||||
* @apiName randomNumber
|
||||
* @apiGroup API
|
||||
* @apiDescription Returns a random number based on an ARO block id.
|
||||
*
|
||||
* @apiParam {numeric} height The height of the block on which the random number will be based on (should be a future block when starting)
|
||||
* @apiParam {numeric} min Minimum number (default 1)
|
||||
* @apiParam {numeric} max Maximum number
|
||||
* @apiParam {string} seed A seed to generate different numbers for each use cases.
|
||||
* @apiSuccess {numeric} data The random number
|
||||
*/
|
||||
|
||||
$height=san($_GET['height']);
|
||||
$max=intval($_GET['max']);
|
||||
if(empty($_GET['min'])) $min=1;
|
||||
else $min=intval($_GET['min']);
|
||||
|
||||
$blk=$db->single("SELECT id FROM blocks WHERE height=:h",array(":h"=>$height));
|
||||
if($blk===false) api_err("Unknown block. Future?");
|
||||
$base=hash("sha256",$blk.$_GET['seed']);
|
||||
|
||||
$seed1=hexdec(substr($base,0,12));
|
||||
// generate random numbers based on the seed
|
||||
mt_srand($seed1,MT_RAND_MT19937 );
|
||||
$res=mt_rand($min, $max);
|
||||
api_echo($res);
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
api_err("Invalid request");
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ define({ "api": [
|
||||
"group": "Success 200",
|
||||
"type": "numeric",
|
||||
"optional": false,
|
||||
"field": "confirmation",
|
||||
"field": "confirmations",
|
||||
"description": "<p>Number of confirmations</p>"
|
||||
},
|
||||
{
|
||||
@@ -771,7 +771,7 @@ define({ "api": [
|
||||
"group": "Success 200",
|
||||
"type": "numeric",
|
||||
"optional": false,
|
||||
"field": "confirmations",
|
||||
"field": "confirmation",
|
||||
"description": "<p>Number of confirmations</p>"
|
||||
},
|
||||
{
|
||||
@@ -889,6 +889,64 @@ define({ "api": [
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=randomNumber",
|
||||
"title": "16. randomNumber",
|
||||
"name": "randomNumber",
|
||||
"group": "API",
|
||||
"description": "<p>Returns a random number based on an ARO block id.</p>",
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "numeric",
|
||||
"optional": false,
|
||||
"field": "height",
|
||||
"description": "<p>The height of the block on which the random number will be based on (should be a future block when starting)</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "numeric",
|
||||
"optional": false,
|
||||
"field": "min",
|
||||
"description": "<p>Minimum number (default 1)</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "numeric",
|
||||
"optional": false,
|
||||
"field": "max",
|
||||
"description": "<p>Maximum number</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "seed",
|
||||
"description": "<p>A seed to generate different numbers for each use cases.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "numeric",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>The random number</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=send",
|
||||
|
||||
@@ -420,7 +420,7 @@
|
||||
"group": "Success 200",
|
||||
"type": "numeric",
|
||||
"optional": false,
|
||||
"field": "confirmation",
|
||||
"field": "confirmations",
|
||||
"description": "<p>Number of confirmations</p>"
|
||||
},
|
||||
{
|
||||
@@ -889,6 +889,64 @@
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=randomNumber",
|
||||
"title": "16. randomNumber",
|
||||
"name": "randomNumber",
|
||||
"group": "API",
|
||||
"description": "<p>Returns a random number based on an ARO block id.</p>",
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "numeric",
|
||||
"optional": false,
|
||||
"field": "height",
|
||||
"description": "<p>The height of the block on which the random number will be based on (should be a future block when starting)</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "numeric",
|
||||
"optional": false,
|
||||
"field": "min",
|
||||
"description": "<p>Minimum number (default 1)</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "numeric",
|
||||
"optional": false,
|
||||
"field": "max",
|
||||
"description": "<p>Maximum number</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "seed",
|
||||
"description": "<p>A seed to generate different numbers for each use cases.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "numeric",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>The random number</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=send",
|
||||
|
||||
@@ -7,7 +7,7 @@ define({
|
||||
"apidoc": "0.3.0",
|
||||
"generator": {
|
||||
"name": "apidoc",
|
||||
"time": "2018-02-22T16:13:41.713Z",
|
||||
"time": "2018-05-09T23:01:25.347Z",
|
||||
"url": "http://apidocjs.com",
|
||||
"version": "0.17.6"
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"apidoc": "0.3.0",
|
||||
"generator": {
|
||||
"name": "apidoc",
|
||||
"time": "2018-02-22T16:13:41.713Z",
|
||||
"time": "2018-05-09T23:01:25.347Z",
|
||||
"url": "http://apidocjs.com",
|
||||
"version": "0.17.6"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user