Async Random Number Generation.
asyncrandom的Python项目详细描述
异步随机
通过调用位于https://qrng.anu.edu.au/API/jsonI.php的端点从anu量子随机数服务器获取一个或多个随机数的实用程序。 使用Tornado Networking框架异步执行请求。
有关如何生成数字的更多信息,请参见https://qrng.anu.edu.au/。
需要龙卷风和它的ioloop才能运行。
安装
下载源并运行安装文件:
python setup.py install
使用量
生成单个随机uint8:
的简单示例def handle_random_int(f): print(f.result()) f = asyncrandom.fetch() f.add_done_callback(handle_random_int) tornado.ioloop.IOLoop.current()
也可以生成多个数字。在本例中,我们生成10:
def handle_random_int(f): print(f.result()) f = asyncrandom.fetch(10) f.add_done_callback(handle_random_int) tornado.ioloop.IOLoop.current().start()
默认情况下,生成8位无符号整数。也可以将其更改为16位。生成10个16位整数的示例:
def handle_random_int(f): print(f.result()) f = asyncrandom.fetch(10, asyncrandom.IntegerType.UINT16) f.add_done_callback(handle_random_int) tornado.ioloop.IOLoop.current()
如果从命令调用,则对服务发出同步调用。可选地,--length和--type可以指定为参数,默认值分别为1和"uint-8"。
命令行示例:
$ asyncrandom --int-type=uint8 --length=1 105