* lib/secrand.rb: rename SecRand() to SecRand.random_number.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3a868301ea
commit
7d061438f1
@ -1,3 +1,7 @@
|
|||||||
|
2007-06-08 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* lib/secrand.rb: rename SecRand() to SecRand.random_number.
|
||||||
|
|
||||||
Fri Jun 8 16:34:20 2007 Tanaka Akira <akr@fsij.org>
|
Fri Jun 8 16:34:20 2007 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/zlib/zlib.c (gzfile_s_open): use FilePathValue to support
|
* ext/zlib/zlib.c (gzfile_s_open): use FilePathValue to support
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# = Secure random number generator interface.
|
# = Secure random number generator interface.
|
||||||
#
|
#
|
||||||
# This library is a interface for secure random number generator which is
|
# This library is a interface for secure random number generator which is
|
||||||
# suitable for HTTP cookies, etc.
|
# suitable for HTTP cookies, nonces, etc.
|
||||||
#
|
#
|
||||||
# It supports following secure random number generators.
|
# It supports following secure random number generators.
|
||||||
#
|
#
|
||||||
@ -16,6 +16,7 @@
|
|||||||
# p SecRand.hex(11) #=> "6aca1b5c58e4863e6b81b8"
|
# p SecRand.hex(11) #=> "6aca1b5c58e4863e6b81b8"
|
||||||
# p SecRand.hex(12) #=> "94b2fff3e7fd9b9c391a2306"
|
# p SecRand.hex(12) #=> "94b2fff3e7fd9b9c391a2306"
|
||||||
# p SecRand.hex(13) #=> "39b290146bea6ce975c37cfc23"
|
# p SecRand.hex(13) #=> "39b290146bea6ce975c37cfc23"
|
||||||
|
# ...
|
||||||
#
|
#
|
||||||
# # random base64 string.
|
# # random base64 string.
|
||||||
# p SecRand.base64(10) #=> "EcmTPZwWRAozdA=="
|
# p SecRand.base64(10) #=> "EcmTPZwWRAozdA=="
|
||||||
@ -94,16 +95,17 @@ module SecRand
|
|||||||
def self.base64(n=nil)
|
def self.base64(n=nil)
|
||||||
[random_bytes(n)].pack("m*").delete("\n")
|
[random_bytes(n)].pack("m*").delete("\n")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# SecRand() generates a random number.
|
# SecRand.random_number generates a random number.
|
||||||
#
|
#
|
||||||
# If an positive integer is given as n,
|
# If an positive integer is given as n,
|
||||||
# SecRand() returns an integer: 0 <= SecRand(n) < n.
|
# SecRand.random_number returns an integer:
|
||||||
|
# 0 <= SecRand.random_number(n) < n.
|
||||||
#
|
#
|
||||||
# If 0 is given or an argument is not given,
|
# If 0 is given or an argument is not given,
|
||||||
# SecRand() returns an float: 0.0 <= SecRand() < 1.0.
|
# SecRand.random_number returns an float:
|
||||||
def SecRand(n=0)
|
# 0.0 <= SecRand.random_number() < 1.0.
|
||||||
|
def self.random_number(n=0)
|
||||||
if 0 < n
|
if 0 < n
|
||||||
hex = n.to_s(16)
|
hex = n.to_s(16)
|
||||||
hex = '0' + hex if (hex.length & 1) == 1
|
hex = '0' + hex if (hex.length & 1) == 1
|
||||||
@ -123,3 +125,4 @@ def SecRand(n=0)
|
|||||||
Math.ldexp(i64 >> (64-Float::MANT_DIG), -Float::MANT_DIG)
|
Math.ldexp(i64 >> (64-Float::MANT_DIG), -Float::MANT_DIG)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user