`
xuanzhui
  • 浏览: 200835 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

真随机数

阅读更多

一般sdk自带的随机数都是伪随机数

 

RANDOM.ORG提供了API可以获取真随机数

 

JSON-RPC API – Release 1

 

首先需要申请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
Your API key, which is used to track the true random bit usage for your client.
n
How many random integers you need. Must be within the [1,1e4] range.
min
The lower boundary for the range from which the random numbers will be picked. Must be within the [-1e9,1e9] range.
max
The upper boundary for the range from which the random numbers will be picked. Must be within the [-1e9,1e9] range.

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)
Specifies whether the random numbers should be picked with replacement. The default (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)
Specifies the base that will be used to display the numbers. Values allowed are 2810 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
This object encapsulates the random numbers and associated data. It contains the following properties.
data
An array containing the sequence of numbers requested. If the request specified 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
A string containing the timestamp in ISO 8601 format at which the request was completed.
bitsUsed
An integer containing the number of true random bits used to complete this request.
bitsLeft
An integer containing the (estimated) number of remaining true random bits available to the client.
requestsLeft
An integer containing the (estimated) number of remaining API requests available to the client.
advisoryDelay
An integer containing the recommended number of milliseconds that the client should delay before issuing another request.

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.

分享到:
评论

相关推荐

    一种基于FPGA的真随机数发生器设计与实现

    真随机数发生器(TRNG)在统计学、信息安全等领域有着广泛的应用。在这些领域中,不仅要求数据序列分布均匀、彼此独立,而且要求其具有不可预测性,能够抵御针对随机性的攻击。B.Sunar,W.J.Marn和D.R.Snson提出,...

    基于FPGA的真随机数发生器设计与实现

    《基于FPGA的真随机数发生器设计与实现》 真随机数发生器(TRNG)在现代科技中扮演着至关重要的角色,特别是在密码学、安全通信和统计模拟等领域。文章详细介绍了如何利用FPGA(Field-Programmable Gate Array,...

    MATLAB下一种获得真随机数方法的研究.pdf

    在这些领域中,随机数的生成是一个重要环节,随机数生成器主要分为两大类:使用数学算法的伪随机数生成器和以物理随机量作为发生源的真随机数生成器。真随机数因为其固有的随机性,在诸如数据加密、信息辅助、智能...

    高速的真随机数发生器

    【高速的真随机数发生器】是一个专门设计用于快速生成随机数的软件工具,其核心特点在于能够以超过200M字节/秒的速度产生随机数据,这在许多需要大量随机数的计算任务中显得尤为关键。在信息技术领域,随机数的生成...

    基于FPGA的真随机数产生器后处理算法的研究.pdf

    在信息安全领域,真随机数生成器(TRNG)扮演了至关重要的角色,因为它们能够为加密系统提供不可预测的安全密钥。一个高质量的随机数对于保证系统安全性至关重要。FPGA(现场可编程门阵列)作为一种通用可编程逻辑...

    C语言生成真正随机数的一个例子

    在C语言中生成随机数是一项常见的任务,尤其在模拟、统计计算或游戏开发等领域。C语言标准库提供了`<stdlib.h>`中的`rand()`函数来生成伪随机数序列,但这些数字并不总是“真正随机”的,而是基于某种可预测的算法。...

    电信设备-基于量子真随机数的移动终端保密系统及方法.zip

    "电信设备-基于量子真随机数的移动终端保密系统及方法"这一主题深入探讨了如何利用量子真随机数生成技术来增强移动终端的安全性。下面将详细阐述相关知识点。 首先,我们要理解什么是量子真随机数。在传统的计算机...

    生成真随机数

    在IT领域,生成真随机数是一项重要的技术,特别是在加密、模拟和游戏开发等场景中。本文将详细讨论C#编程语言中如何生成真随机数,以及相关的关键知识点。 首先,我们要明白“真随机数”与“伪随机数”的区别。真...

    真随机数发生器1.0

    一个比较好的真随机数发生器,大家都来下载啊,谢谢大家

    一种软件生成真随机数的算法研究

    ### 一种软件生成真随机数的算法研究 #### 摘要及背景 本文探讨了随机数的本质,即确保每一个比特位(bit)都具备随机性,并提出了一种基于软件实现的真随机数生成方法。在信息安全、加密解密、模拟仿真等领域中,...

    基于Intel_RNG的真随机数生成器研究

    ### 基于Intel_RNG的真随机数生成器研究 #### 重要概念与背景 在数字安全领域,真随机数生成器(True Random Number Generator, TRNG)扮演着至关重要的角色,尤其是在加密算法、密码学协议以及各种依赖于随机性的...

    物联网嵌入式开发-ESP32实现真随机数发生器(RNG)产生随机数(ESP-IDF +VSCode编程).rar

    1、嵌入式物联网ESP32项目实战开发。例程经过精心编写,简单好用。 2、代码使用Visual Studio Code开发,C语言编程。例程在ESP32-S3上运行。若在其他型号上运行,请自行调整。 3、如果接入其他传感器,请查看发布的...

    linux获取真正随机数源码

    真正随机数(TRNG,True Random Number Generator)与伪随机数(PRNG,Pseudo-Random Number Generator)不同,它基于物理现象,如电子噪声或热噪声,生成无法预测的数值,对于加密算法、密钥生成以及其他安全应用至...

    一种基于FPGA的真随机数发生芯片设计.pdf

    本篇文档讨论了基于现场可编程门阵列(FPGA)的真随机数发生芯片设计。首先,文档提出了随着电子信息技术的发展,对随机数的要求越来越高,特别是对于高随机性和均匀性的要求。传统的伪随机数发生器在应对“不可预测...

    网络游戏-用于生成真随机数的方法和装置以及游戏系统.zip

    在网络游戏领域,真随机数的生成对于确保游戏的公平性和不可预测性至关重要。这份资料“网络游戏-用于生成真随机数的方法和装置以及游戏系统”深入探讨了这一关键议题。真随机数与伪随机数不同,后者是通过算法计算...

    一种软件生成真随机数算法的设计和实现.pdf

    真随机数生成算法的设计和实现 真随机数在信息安全领域有着广泛的应用,例如各种安全认证协议、一次安全通信中使用的会话密钥、软件生成RSA密钥对等,这些应用都会使用到随机数。特别是一些安全级别要求比较高的...

    0.35μm高速真随机数芯片设计.pdf

    在现代信息技术领域中,真随机数(True Random Number,TRNG)在密码学、安全通信、模拟仿真等领域扮演着至关重要的角色。而芯片设计作为硬件实现的基础,在生成真随机数方面尤为关键。本文将详细介绍0.35微米高速真...

    电信设备-基于量子真随机数的通信中继服务器安全设备.zip

    《基于量子真随机数的通信中继服务器安全设备》 在现代信息技术中,通信安全是至关重要的一个环节,尤其在电信行业中,数据的保密性和完整性是保障服务质量和用户隐私的关键。随着科技的进步,传统的加密技术已经...

    基于鼠标移动轨迹的真随机数产生方法_胡亮1

    【基于鼠标移动轨迹的真随机数产生方法】是一种创新的随机数生成算法,它利用了计算机用户在操作鼠标时产生的不可预测运动轨迹作为随机事件源。这种方法与传统的基于鼠标的随机数生成算法相比,其独特之处在于提高了...

Global site tag (gtag.js) - Google Analytics