Adding a convenience method for generating random hexadecimal characters.
git-svn-id: file:///home/svn/framework3/trunk@8233 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
cdaeb27933
commit
d817ac11b4
|
@ -654,6 +654,14 @@ module Text
|
||||||
rand_base(len, bad, *foo )
|
rand_base(len, bad, *foo )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generate random bytes of alphanumeric hex.
|
||||||
|
def self.rand_text_hex(len, bad='')
|
||||||
|
foo = []
|
||||||
|
foo += ('0' .. '9').to_a
|
||||||
|
foo += ('a' .. 'f').to_a
|
||||||
|
rand_base(len, bad, *foo)
|
||||||
|
end
|
||||||
|
|
||||||
# Generate random bytes of numeric data
|
# Generate random bytes of numeric data
|
||||||
def self.rand_text_numeric(len, bad='')
|
def self.rand_text_numeric(len, bad='')
|
||||||
foo = ('0' .. '9').to_a
|
foo = ('0' .. '9').to_a
|
||||||
|
|
|
@ -42,6 +42,7 @@ class Rex::Text::UnitTest < Test::Unit::TestCase
|
||||||
assert_equal('bababbabba', Rex::Text.rand_text(10, nil, 'ab'), 'rand text with specified "good"')
|
assert_equal('bababbabba', Rex::Text.rand_text(10, nil, 'ab'), 'rand text with specified "good"')
|
||||||
assert_equal('MA', Rex::Text.rand_state(), 'rand state')
|
assert_equal('MA', Rex::Text.rand_state(), 'rand state')
|
||||||
assert_equal('xzdttongb.5gfk0xjly3.aak.fmo0rp.com', Rex::Text.rand_hostname(), 'rand hostname')
|
assert_equal('xzdttongb.5gfk0xjly3.aak.fmo0rp.com', Rex::Text.rand_hostname(), 'rand hostname')
|
||||||
|
assert_equal('9aaf811799', Rex::Text.rand_text_hex(10), 'rand hex')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue