Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit e20c80e

Browse files
committed
Prevent rand_numeric allowing leading zeros by default
1 parent 5abb4a5 commit e20c80e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/wpxf/utility/text.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ module Utility
88
module Text
99
# Generate a random numeric string.
1010
# @param length [Integer] the number of characters to include.
11+
# @param allow_leading_zero [Boolean] if set to true, will allow a number starting with zero.
1112
# @return [String] a random numeric string.
12-
def self.rand_numeric(length)
13-
Array.new(length) { [*'0'..'9'].sample }.join
13+
def self.rand_numeric(length, allow_leading_zero = false)
14+
value = Array.new(length) { [*'0'..'9'].sample }.join
15+
value[0] = [*'1'..'9'].sample unless allow_leading_zero
16+
value
1417
end
1518

1619
# Generate a random alphanumeric string.

0 commit comments

Comments
 (0)