Random generation of variable sized test files

automated-tests, bash

Solution

This will generate 500 files each containing between 1 and 10 megabytes of random bytes.

#!/bin/bash
max=10    # number of megabytes
for ((counter=1; counter<=500; counter++))
do
    echo Creating file$counter
    dd bs=1M count=$(($RANDOM%max + 1)) if=/dev/urandom of=file$counter
done

The second line could instead be:

for counter in {1..500}

Problem

Here is script i am planning to use to generate 500 test files populated with random data. ``` for((counter=1;counter<=500;counter++)); do echo Creating file$counter; dd bs=1M count=10 if=/dev/urandom of=file$counter; done ``` But what i need the script to do is make those 500 files to be of variable size as in let say between 1M and 10M; ie, file1=1M, file2=10M, file3=9M etc … any help?

Original source