一般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提出,...
《基于FPGA的真随机数发生器设计与实现》 真随机数发生器(TRNG)在现代科技中扮演着至关重要的角色,特别是在密码学、安全通信和统计模拟等领域。文章详细介绍了如何利用FPGA(Field-Programmable Gate Array,...
为了满足这些领域对于随机数的大量需求,科学家和工程师们开发了多种随机数生成工具,而其中最为突出的,莫过于能够在极高速度下生成随机数的“高速的真随机数发生器”。 真随机数发生器(True Random Number ...
在这些领域中,随机数的生成是一个重要环节,随机数生成器主要分为两大类:使用数学算法的伪随机数生成器和以物理随机量作为发生源的真随机数生成器。真随机数因为其固有的随机性,在诸如数据加密、信息辅助、智能...
在信息安全领域,真随机数生成器(TRNG)扮演了至关重要的角色,因为它们能够为加密系统提供不可预测的安全密钥。一个高质量的随机数对于保证系统安全性至关重要。FPGA(现场可编程门阵列)作为一种通用可编程逻辑...
在C语言中生成随机数是一项常见的任务,尤其在模拟、统计计算或游戏开发等领域。C语言标准库提供了`<stdlib.h>`中的`rand()`函数来生成伪随机数序列,但这些数字并不总是“真正随机”的,而是基于某种可预测的算法。...
"电信设备-基于量子真随机数的移动终端保密系统及方法"这一主题深入探讨了如何利用量子真随机数生成技术来增强移动终端的安全性。下面将详细阐述相关知识点。 首先,我们要理解什么是量子真随机数。在传统的计算机...
在IT领域,生成真随机数是一项重要的技术,特别是在加密、模拟和游戏开发等场景中。本文将详细讨论C#编程语言中如何生成真随机数,以及相关的关键知识点。 首先,我们要明白“真随机数”与“伪随机数”的区别。真...
一个比较好的真随机数发生器,大家都来下载啊,谢谢大家
### 一种软件生成真随机数的算法研究 #### 摘要及背景 本文探讨了随机数的本质,即确保每一个比特位(bit)都具备随机性,并提出了一种基于软件实现的真随机数生成方法。在信息安全、加密解密、模拟仿真等领域中,...
### 基于Intel_RNG的真随机数生成器研究 #### 重要概念与背景 在数字安全领域,真随机数生成器(True Random Number Generator, TRNG)扮演着至关重要的角色,尤其是在加密算法、密码学协议以及各种依赖于随机性的...
1、嵌入式物联网ESP32项目实战开发。例程经过精心编写,简单好用。 2、代码使用Visual Studio Code开发,C语言编程。例程在ESP32-S3上运行。若在其他型号上运行,请自行调整。 3、如果接入其他传感器,请查看发布的...
真正随机数(TRNG,True Random Number Generator)与伪随机数(PRNG,Pseudo-Random Number Generator)不同,它基于物理现象,如电子噪声或热噪声,生成无法预测的数值,对于加密算法、密钥生成以及其他安全应用至...
本篇文档讨论了基于现场可编程门阵列(FPGA)的真随机数发生芯片设计。首先,文档提出了随着电子信息技术的发展,对随机数的要求越来越高,特别是对于高随机性和均匀性的要求。传统的伪随机数发生器在应对“不可预测...
在网络游戏领域,真随机数的生成对于确保游戏的公平性和不可预测性至关重要。这份资料“网络游戏-用于生成真随机数的方法和装置以及游戏系统”深入探讨了这一关键议题。真随机数与伪随机数不同,后者是通过算法计算...
真随机数生成算法的设计和实现 真随机数在信息安全领域有着广泛的应用,例如各种安全认证协议、一次安全通信中使用的会话密钥、软件生成RSA密钥对等,这些应用都会使用到随机数。特别是一些安全级别要求比较高的...
在现代信息技术领域中,真随机数(True Random Number,TRNG)在密码学、安全通信、模拟仿真等领域扮演着至关重要的角色。而芯片设计作为硬件实现的基础,在生成真随机数方面尤为关键。本文将详细介绍0.35微米高速真...
《基于量子真随机数的通信中继服务器安全设备》 在现代信息技术中,通信安全是至关重要的一个环节,尤其在电信行业中,数据的保密性和完整性是保障服务质量和用户隐私的关键。随着科技的进步,传统的加密技术已经...
【基于鼠标移动轨迹的真随机数产生方法】是一种创新的随机数生成算法,它利用了计算机用户在操作鼠标时产生的不可预测运动轨迹作为随机事件源。这种方法与传统的基于鼠标的随机数生成算法相比,其独特之处在于提高了...