Module: Ronin::Support::Text::Random
- Defined in:
- lib/ronin/support/text/random.rb,
lib/ronin/support/text/random/mixin.rb
Overview
Methods for generating random text.
Defined Under Namespace
Modules: Mixin
Class Method Summary collapse
-
.alpha(n = 1) ⇒ String
A random alphabetic string.
-
.alpha_numeric(n = 1) ⇒ String
A random alpha-numeric string.
-
.ascii(n = 1) ⇒ String
A random ASCII string.
-
.control(n = 1) ⇒ String
A random control-character string.
-
.digits(n = 1) ⇒ String
Alias for Random.numeric.
-
.hex(n = 1) ⇒ String
A random hexadecimal string.
-
.lower_alpha(n = 1) ⇒ String
Alias for Random.lowercase_alpha.
-
.lower_hex(n = 1) ⇒ String
Alias for Random.lowercase_hex.
-
.lowercase_alpha(n = 1) ⇒ String
The lower-case alphabetic character set.
-
.lowercase_hex(n = 1) ⇒ String
The lower-case hexadecimal character set.
-
.numeric(n = 1) ⇒ String
Generates a random String of numeric characters.
-
.octal(n = 1) ⇒ String
A random octal-digit string.
-
.printable(n = 1) ⇒ String
The set of printable characters, including spaces.
-
.punctuation(n = 1) ⇒ String
A random punctuation string.
-
.signed_ascii(n = 1) ⇒ String
The signed ASCII character set.
-
.space(n = 1) ⇒ String
A random whitespace string.
-
.swapcase(string) ⇒ String
Creates a new String by randomizing the case of each character in the string.
-
.symbols(n = 1) ⇒ String
A random symbolic string.
-
.upper_alpha(n = 1) ⇒ String
Alias for Random.uppercase_alpha.
-
.upper_hex(n = 1) ⇒ String
Alias for Random.uppercase_hex.
-
.uppercase_alpha(n = 1) ⇒ String
The upper-case alphabetic character set.
-
.uppercase_hex(n = 1) ⇒ String
The upper-case hexadecimal character set.
-
.visible(n = 1) ⇒ String
The set of printable characters, not including spaces.
-
.whitespace(n = 1) ⇒ String
A random whitespace string.
Class Method Details
.alpha(n = 1) ⇒ String
A random alphabetic string.
264 265 266 |
# File 'lib/ronin/support/text/random.rb', line 264 def self.alpha(n=1) Chars::ALPHA.random_string(n) end |
.alpha_numeric(n = 1) ⇒ String
A random alpha-numeric string.
279 280 281 |
# File 'lib/ronin/support/text/random.rb', line 279 def self.alpha_numeric(n=1) Chars::ALPHA_NUMERIC.random_string(n) end |
.ascii(n = 1) ⇒ String
A random ASCII string.
413 414 415 |
# File 'lib/ronin/support/text/random.rb', line 413 def self.ascii(n=1) Chars::ASCII.random_string(n) end |
.control(n = 1) ⇒ String
A random control-character string.
383 384 385 |
# File 'lib/ronin/support/text/random.rb', line 383 def self.control(n=1) Chars::CONTROL.random_string(n) end |
.digits(n = 1) ⇒ String
Alias for numeric.
99 100 101 |
# File 'lib/ronin/support/text/random.rb', line 99 def self.digits(n=1) numeric(n) end |
.hex(n = 1) ⇒ String
A random hexadecimal string.
189 190 191 |
# File 'lib/ronin/support/text/random.rb', line 189 def self.hex(n=1) Chars::HEXADECIMAL.random_string(n) end |
.lower_alpha(n = 1) ⇒ String
Alias for lowercase_alpha.
249 250 251 |
# File 'lib/ronin/support/text/random.rb', line 249 def self.lower_alpha(n=1) lowercase_alpha(n) end |
.lower_hex(n = 1) ⇒ String
Alias for lowercase_hex.
174 175 176 |
# File 'lib/ronin/support/text/random.rb', line 174 def self.lower_hex(n=1) lowercase_hex(n) end |
.lowercase_alpha(n = 1) ⇒ String
The lower-case alphabetic character set.
234 235 236 |
# File 'lib/ronin/support/text/random.rb', line 234 def self.lowercase_alpha(n=1) Chars::LOWERCASE_ALPHA.random_string(n) end |
.lowercase_hex(n = 1) ⇒ String
The lower-case hexadecimal character set.
159 160 161 |
# File 'lib/ronin/support/text/random.rb', line 159 def self.lowercase_hex(n=1) Chars::LOWERCASE_HEXADECIMAL.random_string(n) end |
.numeric(n = 1) ⇒ String
Generates a random String of numeric characters.
84 85 86 |
# File 'lib/ronin/support/text/random.rb', line 84 def self.numeric(n=1) Chars::NUMERIC.random_string(n) end |
.octal(n = 1) ⇒ String
A random octal-digit string.
114 115 116 |
# File 'lib/ronin/support/text/random.rb', line 114 def self.octal(n=1) Chars::OCTAL.random_string(n) end |
.printable(n = 1) ⇒ String
The set of printable characters, including spaces.
368 369 370 |
# File 'lib/ronin/support/text/random.rb', line 368 def self.printable(n=1) Chars::PRINTABLE.random_string(n) end |
.punctuation(n = 1) ⇒ String
A random punctuation string.
294 295 296 |
# File 'lib/ronin/support/text/random.rb', line 294 def self.punctuation(n=1) Chars::PUNCTUATION.random_string(n) end |
.signed_ascii(n = 1) ⇒ String
The signed ASCII character set.
398 399 400 |
# File 'lib/ronin/support/text/random.rb', line 398 def self.signed_ascii(n=1) Chars::SIGNED_ASCII.random_string(n) end |
.space(n = 1) ⇒ String
A random whitespace string.
338 339 340 |
# File 'lib/ronin/support/text/random.rb', line 338 def self.space(n=1) whitespace(n) end |
.swapcase(string) ⇒ String
Creates a new String by randomizing the case of each character in the string.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ronin/support/text/random.rb', line 52 def self.swapcase(string) candidates = [] string.each_char.with_index do |char,index| if char =~ /\p{L}/ candidates << index end end new_string = string.dup # ensure that at least one character is swap-cased, but not all num_swaps = rand(1..(candidates.length - 1)) || 1 candidates.sample(num_swaps).each do |index| new_string[index] = new_string[index].swapcase end return new_string end |
.symbols(n = 1) ⇒ String
A random symbolic string.
309 310 311 |
# File 'lib/ronin/support/text/random.rb', line 309 def self.symbols(n=1) Chars::SYMBOLS.random_string(n) end |
.upper_alpha(n = 1) ⇒ String
Alias for uppercase_alpha.
219 220 221 |
# File 'lib/ronin/support/text/random.rb', line 219 def self.upper_alpha(n=1) uppercase_alpha(n) end |
.upper_hex(n = 1) ⇒ String
Alias for uppercase_hex.
144 145 146 |
# File 'lib/ronin/support/text/random.rb', line 144 def self.upper_hex(n=1) uppercase_hex(n) end |
.uppercase_alpha(n = 1) ⇒ String
The upper-case alphabetic character set.
204 205 206 |
# File 'lib/ronin/support/text/random.rb', line 204 def self.uppercase_alpha(n=1) Chars::UPPERCASE_ALPHA.random_string(n) end |
.uppercase_hex(n = 1) ⇒ String
The upper-case hexadecimal character set.
129 130 131 |
# File 'lib/ronin/support/text/random.rb', line 129 def self.uppercase_hex(n=1) Chars::UPPERCASE_HEXADECIMAL.random_string(n) end |
.visible(n = 1) ⇒ String
The set of printable characters, not including spaces.
353 354 355 |
# File 'lib/ronin/support/text/random.rb', line 353 def self.visible(n=1) Chars::VISIBLE.random_string(n) end |
.whitespace(n = 1) ⇒ String
A random whitespace string.
324 325 326 |
# File 'lib/ronin/support/text/random.rb', line 324 def self.whitespace(n=1) Chars::WHITESPACE.random_string(n) end |