I get wildly different real times
when I run the following command.
dd if=/dev/random bs=1k count=1
It doesn' happen for if=/dev/null
, nor does it happen for if=/dev/urandom
I've run it 500 times. Here are the general stats (per call). The times are in seconds.
Minimum Maximum Average Median
00.002 89.999 4.50402 2.275
Does anyone have any suggestions about why this may be happening?
The system is Ubuntu 10.04 desktop. Bash version is 4.1.5(1)
It also shows the similar wild fluctuations in a VirtualBox VM running the same version of Ubuntu.
Here is the actual test code
cp /dev/null "$HOME/dd-random.secs"
for ((i=100;i<=500;i++)); do
if ((i<10)) ;then zi="00$i"
elif ((i<100)) ;then zi="0$i"
else zi="$i"
fi
echo -ne "$zi\t" >>"$HOME/dd-random.secs"
exec 3>/dev/null 4>/dev/null
{ time { dd if=/dev/random bs=1k count=1; } 1>&3 2>&4; } 2>&1 |tail -n 3|tr 'm\n' '\t' |sed -re "s/([0-9])s/\1/g" >>"$HOME/dd-random.secs"
exec 3>&- 4>&-
echo >>"$HOME/dd-random.secs"
done
/dev/random
and/dev/random
, I highly recommend reading Is a rand from /dev/urandom secure for a login key? (“The short answer is yes. The long answer is also yes.”)./dev/null
for reading - it is a sink, not a source. For empty (zero) input, use/dev/zero
./dev/null
can be a source (immediately returning EOF) and is the right one here. However using: > ~/did-random.secs
is a clearer way to create or truncate a file.