一般sdk自带的随机数都是伪随机数
RANDOM.ORG提供了API可以获取真随机数
首先需要申请key
调用API的url https://api.random.org/json-rpc/1/invoke
python测试
>>> base_url='https://api.random.org/json-rpc/1/invoke' >>> import requests >>> req_dict={'jsonrpc':'2.0','method':'generateIntegers','id':'1111'} >>> req_dict['params']={'apiKey':'your_own_key','n':1,'min':1,'max':100} >>> resp = requests.post(base_url,json=req_dict) >>> resp.json() {'jsonrpc': '2.0', 'result': {'advisoryDelay': 40, 'bitsUsed': 7, 'bitsLeft': 249993, 'requestsLeft': 999, 'random': {'completionTime': '2016-01-28 07:14:50Z', 'data': [26]}}, 'id': '1111'} >>> resp_dict = resp.json() >>> resp_dict['result']['random']['data'] [26]
获取一个简单的int类型随机数的API详细说明
里面有个比较重要的optional参数replacement,设置replacement=false表示不可以有重复的
generateIntegers
This method generates true random integers within a user-defined range. Your client must set the method
property of its JSON-RPC request object to generateIntegers
. The request must also contain an id
member, which will be returned in the response.
Required Parameters
The following parameters are mandatory and should be specified in the params
array of the JSON-RPC request:
apiKey
n
min
max
Optional Parameters
The following parameters are optional and can be included in the params
object of your JSON-RPC request if you want functionality that is different from the default:
replacement
(default value true
)true
) will cause the numbers to be picked with replacement, i.e., the resulting numbers may contain duplicate values (like a series of dice rolls). If you want the numbers picked to be unique (like raffle tickets drawn from a container), set this value to false
.base
(default value 10
)2
, 8
, 10
and 16
. This affects the JSON types and formatting of the resulting data as discussed below.Successful Response
If the numbers were generated successfully, RANDOM.ORG returns a JSON-RPC response with the result
property containing an object with the following named values:
random
data
base
10
(or did not specify a base and therefore defaults to 10
), the elements in the array will be integers. Because JSON (according to RFC4627) only allows numbers to be written as decimal, the numbers will be typed as strings if a different base
than 10
was specified in the request. Numbers in any base other than 10
will be padded with leading zeros up to the width required to display the chosen range.completionTime
bitsUsed
bitsLeft
requestsLeft
advisoryDelay
For a successful response, the error
property is absent.
Simple clients may not necessarily need all of the properties in the response. A minimal client could use only the random.data
andadvisoryDelay
properties and ignore the rest of the response.
Error Response
If an error occurred, RANDOM.ORG returns a JSON-RPC response in which the result
property is absent and the error
property contains an error object as described in Error Codes and Messages.
Example 1
The following requests six numbers in the [1,6] range. The replacement
parameter is set to true
, which means the numbers will be picked with replacement, i.e., can contain duplicate values. This makes them suitable for use as dice rolls.
{ "jsonrpc": "2.0", "method": "generateIntegers", "params": { "apiKey": "6b1e65b9-4186-45c2-8981-b77a9842c4f0", "n": 6, "min": 1, "max": 6, "replacement": true }, "id": 42 }
The service responds with the following:
{ "jsonrpc": "2.0", "result": { "random": { "data": [ 1, 5, 4, 6, 6, 4 ], "completionTime": "2011-10-10 13:19:12Z" }, "bitsUsed": 16, "bitsLeft": 199984, "requestsLeft": 9999, "advisoryDelay": 0 }, "id": 42 }
The random
object contains the true random values (in the data
array) produced as well as the completion time. Note that thecompletionTime
specifies UTC time zone (‘Zulu time’) by the letter ‘Z’ after the clock time. Through the other fields in the result
object, RANDOM.ORG also advises how many true random bits were used to satisfy the request (16) and how many bits (199,984) and requests (9,999) are left in the client's quota. It also advises the client that it can go ahead and issue the next request without delay (0 milliseconds).
Example 2
The following requests 52 numbers in the [1,52] range. The replacement
parameter is set to false
, meaning the numbers will be picked without replacement, i.e., duplicates will not occur. This makes them suitable to shuffle a deck of cards.
{ "jsonrpc": "2.0", "method": "generateIntegers", "params": { "apiKey": "6b1e65b9-4186-45c2-8981-b77a9842c4f0", "n": 52, "min": 1, "max": 52, "replacement": false }, "id": 3076 }
The service responds with the following:
{ "jsonrpc": "2.0", "result": { "random": { "data": [ 39, 24, 18, 46, 6, 52, 36, 30, 40, 42, 37, 4, 7, 20, 1, 44, 25, 9, 21, 29, 51, 41, 14, 15, 48, 50, 31, 17, 3, 19, 45, 35, 2, 43, 26, 16, 5, 23, 12, 8, 10, 47, 13, 33, 34, 49, 22, 11, 28, 27, 38, 32 ], "completionTime": "2011-10-10 13:19:12Z", }, "bitsUsed": 296, "bitsLeft": 199704, "requestsLeft": 9999, "advisoryDelay": 2000 }, "id": 3076 }
The random
object contains the true random numbers (in the data
array) produced, as well as the completion time.
The remaining fields in the result
object indicate how many true random bits were used to satisfy the request as well as how many bits and requests are left in the client's quota. The response also advises the client preferably to delay at least two seconds before issuing a new request.
Example 3
The following requests 512 bytes, i.e., numbers in the [0,255] range. No replacement
parameter is given, which means the service will use the default value of true
and the numbers will be picked with replacement, i.e., duplicates are allowed. The optional base
parameter is used to indicate that the client wishes the numbers to be returned in hexadecimal form. The numbers could be used as seed material for a pseudo-random number generator.
{ "jsonrpc": "2.0", "method": "generateIntegers", "params": { "apiKey": "6b1e65b9-4186-45c2-8981-b77a9842c4f0", "n": 512, "min": 0, "max": 255, "base": 16 }, "id": 4352 }
The service responds with the following:
{ "jsonrpc": "2.0", "result": { "random": { "data": [ "90", "a6", "3e", "f7", "06", ... ], "completionTime": "2011-10-10 13:19:12Z" }, "bitsUsed": 4096, "bitsLeft": 195904, "requestsLeft": 9999, "advisoryDelay": 0 }, "id": 4352 }
The random
object contains the random data generated by the server. For brevity, only the first five bytes are shown in the response. Note that the data
array contains strings rather than integers, because the numbers are formatted in base 16.
The service also advises how many true random bits were used to satisfy the request and how many bits and requests are left in the client's quota.
相关推荐
真随机数发生器(TRNG)在统计学、信息安全等领域有着广泛的应用。在这些领域中,不仅要求数据序列分布均匀、彼此独立,而且要求其具有不可预测性,能够抵御针对随机性的攻击。B.Sunar,W.J.Marn和D.R.Snson提出,...
C语言生成真正随机数,可设定均匀分布随机数的区间
一个比较好的真随机数发生器,大家都来下载啊,谢谢大家
MATLAB下一种获得真随机数方法的研究.pdf
基于FPGA的真随机数产生器后处理算法的研究.pdf
电信设备-基于量子真随机数的移动终端保密系统及方法.zip
这是对计算机计数器采样配合随机函数获得随机数方法的具体应用,随机数生成速度大于200M字节/秒。你输入文件大小后,就可以建立文件了。程序界面有使用方法。
WNG6 是由北京芯光天地集成电路设计有限公司研制的一款高性能真随机 数产生器芯片,其技术性能指标处于当前国内领先水平。该芯片可以广泛用于信 息安全、密码设备、仿真模拟等应用领域
真随机数熵评估最小熵检测工具
简单的生成真随机数dll,C#编写,。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
设计并实现了一种基于FPGA的真随机数发生器,利用一对振荡环路之间的相位漂移和抖动以及亚稳态作为随机源,使用线性反馈移位寄存器的输出与原始序列运算作为后续处理。在Xilinx Virtex-5平台的测试实验中,探讨了...
一种软件生成真随机数的算法研究一种软件生成真随机数的算法研究一种软件生成真随机数的算法研究
linux获取真正随机数源码
本程序可以快速产生高质量真随机数,生成速率在每秒200M字节以上。
基于Intel_RNG的真随机数生成器研究
给出一种运用计算机中鼠标移动轨迹这一随机事件产生真随机数的算法,与传统基于鼠标的随机数生成算法相比,在采样原始数据过程中,该方法得到的数据随机性更高,与其他用物理过程产生真随机数的算法相比,不用接额外的...
本文分析了常用的两类随机数发生器,指出了并非硬件随机数即为真随机数,提出了硬件真随机数发生器的实现原理和评测准则。
有趣的真随机数抽取guid 双色球例子,从第n个开始取m个。
0.35μm高速真随机数芯片设计.pdf