linux中生成随机数_如何在Linux中生成随机数?

linux中生成随机数

linux中生成随机数

Generating random numbers can seem odd. But it is very important for security. Insecurity field whatever best cipher or algorithm you use if you can’t generate random numbers it is useless from point of view of security. So how can we generate random numbers in a Linux environment?

生成随机数似乎很奇怪。 但这对于安全性非常重要。 如果无法生成随机数,无论使用哪种最佳密码或算法,“不安全性”字段从安全性的角度来看都是没有用的。 那么我们如何在Linux环境中生成随机数呢?

用urandom生成
文件
(Generate With urandom File)

urandom is a device which resides under the /dev . We can read this file which will output some binary values. We can use cat or similar command to print or redirect into a file.

urandom是位于/dev下的设备。 我们可以读取此文件,该文件将输出一些二进制值。 我们可以使用cat或类似的命令来打印或重定向到文件中。

$ cat /dev/urandom
Generate With urandom File
Generate With urandom File
用urandom文件生成

使用Openssl生成随机数(Generate Random Numbers With Openssl)

The second option is to use OpenSSL which is a core security library for a lot of application. OpenSSL rand 256 commands will generate 256 bytes of random data with the binary format. to generate more readable format like hex use -hex option  rand -hex 256.

第二种选择是使用OpenSSL,它是许多应用程序的核心安全性库。 OpenSSL rand 256命令将以二进制格式生成256字节的随机数据。 要生成更易读的格式(例如十六进制),请使用-hex选项rand -hex 256

$ openssl rand -hex 256
Generate With Openssl
Generate With Openssl
用Openssl生成

使用Python生成随机数(Generate Random Numbers With Python)

The third option is using python random library. But this library generates random numbers rather than random data. We will use random module and random() function like below. This will generate a random number between 1 and 0.

第三种选择是使用python随机库。 但是该库生成随机数,而不是随机数据。 我们将使用如下所示的random模块和random()函数。 这将生成一个介于1和0之间的随机数。

import random
random.random()
Generate With Python
Generate With Python
用Python生成
LEARN MORE  How To Discover Network Hosts With Nmap?
了解更多如何使用Nmap发现网络主机?

翻译自: https://www.poftut.com/generate-random-numbers-linux/

linux中生成随机数

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值