Bash script to generate random ascii lines whose lengths are also random but within the range 'min_line_len' - 'max_line_len'.
From: Amit
Date: Sat Mar 28 2026 - 08:16:30 EST
Bash script to generate random ascii lines whose lengths are also
random but within the range 'min_line_len' - 'max_line_len'.
---------------------------------------------------------------------------------------------------
generate_random_ascii_lines_having_randon_lengths_within_a_range.sh
---------------------------------------------------------------------------------------------------
#!/bin/bash
# Author: Amit Choudhary
# Email: amitchoudhary0523 AT gmail DOT com
#
# Description: This bash script generates random ascii lines whose lengths are
# also random but within the range 'min_line_len' - 'max_line_len'.
#
# Example usage:
# ./generate_random_ascii_lines_having_randon_lengths_within_a_range.sh
#
min_line_len=8000
max_line_len=30000
let "modulus = max_line_len - min_line_len + 1"
#echo "DEBUG: modulus = $modulus"
lines_curr_count=0
total_lines_to_print=100
while [ "$lines_curr_count" -lt "$total_lines_to_print" ]; do
let "curr_line_len = min_line_len + (RANDOM % modulus)"
#echo "DEBUG: Length of line to create = $curr_line_len"
line=""
# The following has to be done because the terminal restricts the input of
# any command (here, it is "dd" command) to only 4096 characters (including
# new line character). So, to circumvent this restriction, the following has
# been done the way it has been done.
while [ "$curr_line_len" -gt 4000 ]; do
temp=`tr -dc '[:print:]' < /dev/urandom | dd ibs=4000 count=1 \
status=none;`
line=$line$temp
let "curr_line_len-=4000"
done
#echo "DEBUG: Length of line 'remaining' to create = $curr_line_len"
if [ "$curr_line_len" -gt 0 ]; then
temp=`tr -dc '[:print:]' < /dev/urandom | dd ibs=$curr_line_len \
count=1 status=none;`
line=$line$temp
fi
#echo "DEBUG: Length of line = ${#line}"
echo $line
let "lines_curr_count++"
done
--------------------------------------------------------------------------------