method
random_bytes
v2_1_10 -
Show latest stable
-
0 notes -
Class: SecureRandom
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10 (1)
- 2_2_9 (0)
- 2_4_6
- 2_5_5
- 2_6_3
- What's this?
random_bytes(n=nil)
public
SecureRandom.random_bytes generates a random binary string.
The argument n specifies the length of the result string.
If n is not specified or is nil, 16 is assumed. It may be larger in future.
The result may contain any byte: “x00” - “xff”.
p SecureRandom.random_bytes #=> "\xD8\\\xE0\xF4\r\xB2\xFC*WM\xFF\x83\x18\xF45\xB6" p SecureRandom.random_bytes #=> "m\xDC\xFC/\a\x00Uf\xB2\xB2P\xBD\xFF6S\x97"
If secure random number generator is not available, NotImplementedError is raised.