ASIC/FPGA Design and Verification Out Source Services
simple bash script, which demonstrates a generation of random number within a specified range
- The scripts generates a random number within a user specified range.
- The random number, in this example, is used to find a file and touch it.
- The script is shown below:
#!/bin/bash
rnd_max="32767"
num_file=`find my_web -name "*.html" | wc -l`
#generate a random number within range
idx_file=$(($num_file * $RANDOM))
idx_file=$(($idx_file / $rnd_max))
cnt="0"
for f in $(find my_web -name "*.html"); do
if [ "$cnt" -eq "$idx_file" ] ; then
cmd="touch "$f
echo $cmd
eval $cmd
fi
cnt=$[$cnt+1] #increment
done
Please let me know what you think on my site.
Contact me now at: |