Skip to content

Commit

Permalink
test-lib: add ct_random_string function
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup authored and pkubatrh committed Mar 6, 2018
1 parent cef6837 commit 6adc2c4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,17 @@ function ct_assert_cmd_failure() {
echo " PASS"
return 0
}


# ct_random_string [LENGTH=10]
# ----------------------------
# Generate pseudorandom alphanumeric string of LENGTH bytes, the
# default length is 10. The string is printed on stdout.
ct_random_string()
(
export LC_ALL=C
dd if=/dev/urandom count=1 bs=10k 2>/dev/null \
| tr -dc 'a-z0-9' \
| fold -w "${1-10}" \
| head -n 1
)

0 comments on commit 6adc2c4

Please sign in to comment.