| Server IP : 162.214.74.102 / Your IP : 216.73.217.21 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /proc/self/root/opt/cpanel/ea-ruby24/root/usr/share/ri/system/Random/Formatter/ |
Upload File : |
U:RDoc::AnyMethod[iI" uuid:EFI"Random::Formatter#uuid;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Verbatim; [1I"=# SecureRandom.random_number generates a random number.
;TI"#
;TI".# If a positive integer is given as _n_,
;TI"C# +SecureRandom.random_number+ returns an integer, such that:
;TI"1# +0 <= SecureRandom.random_number(n) < n+.
;TI"#
;TI"2# p SecureRandom.random_number(100) #=> 15
;TI"2# p SecureRandom.random_number(100) #=> 88
;TI"#
;TI"2# If 0 is given or an argument is not given,
;TI"@# +SecureRandom.random_number+ returns a float, such that:
;TI"4# +0.0 <= SecureRandom.random_number() < 1.0+.
;TI"#
;TI"<# p SecureRandom.random_number #=> 0.596506046187744
;TI"<# p SecureRandom.random_number #=> 0.350621695741409
;TI"#
;TI"def random_number(n=0)
;TI" if 0 < n
;TI"! if defined? OpenSSL::BN
;TI"* OpenSSL::BN.rand_range(n).to_i
;TI" else
;TI" hex = n.to_s(16)
;TI"4 hex = '0' + hex if (hex.length & 1) == 1
;TI"" bin = [hex].pack("H*")
;TI" mask = bin[0].ord
;TI" mask |= mask >> 1
;TI" mask |= mask >> 2
;TI" mask |= mask >> 4
;TI" begin
;TI", rnd = random_bytes(bin.length)
;TI". rnd[0] = (rnd[0].ord & mask).chr
;TI" end until rnd < bin
;TI"# rnd.unpack("H*")[0].hex
;TI"
end
;TI" else
;TI"- # assumption: Float::MANT_DIG <= 64
;TI"! if defined? OpenSSL::BN
;TI"/ i64 = OpenSSL::BN.rand(64, -1).to_i
;TI" else
;TI"0 i64 = random_bytes(8).unpack("Q")[0]
;TI"
end
;TI"C Math.ldexp(i64 >> (64-Float::MANT_DIG), -Float::MANT_DIG)
;TI" end
;TI" end
;T:@format0o:RDoc::Markup::Paragraph; [I"U# SecureRandom.uuid generates a random v4 UUID (Universally Unique IDentifier). ;TI"# ;TI"H# p SecureRandom.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594" ;TI"H# p SecureRandom.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab" ;TI"H# p SecureRandom.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b" ;TI"# ;TI"A# The version 4 UUID is purely random (except the version). ;TI"Y# It doesn't contain meaningful information such as MAC addresses, timestamps, etc. ;TI"# ;TI"A# The result contains 122 random bits (15.25 random bytes). ;TI"# ;TI")# See RFC 4122 for details of UUID. ;TI"#;T:
@fileI"lib/securerandom.rb;T:0@omit_headings_from_table_of_contents_below000[ I"();T@HFI"Formatter;FcRDoc::NormalModule00