SecureRandom加密的强随机数生成器

来源:互联网 发布:vb for mac下载 编辑:程序博客网 时间:2024/04/27 16:01

(1)base64(n=nil)

::base64 generates a random base64 string.

The argument n specifies the length of the random length. The length of the result string is about 4/3 of n.

If n is not specified, 16 is assumed. It may be larger in future.

The result may contain A-Z, a-z, 0-9, “+”, “/” and “=”.

p SecureRandom.base64 #=> "/2BuBuLf3+WfSKyQbRcc/A=="p SecureRandom.base64 #=> "6BbW0pxO0YENxn38HMUbcQ=="

(2)hex(n=nil)

::hex generates a random hex string.

The argument n specifies the length of the random length. The length of the result string is twice of n.

If n is not specified, 16 is assumed. It may be larger in future.

The result may contain 0-9 an

<span style="font-size:14px;">p SecureRandom.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"p SecureRandom.hex #=> "91dc3bfb4de5b11d029d376634589b61"</span>

(3)uuid()

::uuid generates a v4 random UUID (Universally Unique IDentifier).

p SecureRandom.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"p SecureRandom.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"p SecureRandom.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"


0 0
原创粉丝点击