开发者

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;cou开发者_C百科nter++));
          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?


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}


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜