Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random generation of variable sized test files

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?

like image 628
deepseefan Avatar asked Jan 21 '23 23:01

deepseefan


1 Answers

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}
like image 159
Dennis Williamson Avatar answered Jan 31 '23 05:01

Dennis Williamson