Randomly generating variable size test files

Here is the script I plan to use to create 500 test files filled 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 I need a script to make these 500 files have a variable size, for example, between 1M and 10M; those. file1 = 1M, file2 = 10M, file3 = 9M, etc.

any help?

+4
source share
3 answers

This will generate 500 files, each of which contains from 1 to 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 may be as follows:

 for counter in {1..500} 
+4
source
 set MAX=10 for((counter=1;counter<=500;counter++)); do echo "Creating file$counter" dd bs=$(( ($RANDOM%$MAX)+1 ))M count=10 if=/dev/urandom of=file$counter done 
+3
source

Try $((1+$RANDOM%$MAX))

+1
source

All Articles