首页 > 代码库 > SecureRandom加密的强随机数生成器

SecureRandom加密的强随机数生成器

http://www.ruby-doc.org/stdlib-1.9.3/libdoc/securerandom/rdoc/SecureRandom.html

 

(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 and a-f.

p SecureRandom.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"p SecureRandom.hex #=> "91dc3bfb4de5b11d029d376634589b61"

(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"

 

SecureRandom加密的强随机数生成器