Quote:>Hi, I'm trying to get something like this
>for i=1 to any number
>{
> a=random number generator between 1 and 2^16;
> program a
>}
>I would appreciate any help, the idea is to run a C program that accepts
>as an argument a number between 1 ant 2^16, several times
>Thank you
hopefully you have $RANDOM otherwise you will have to make a function
for it. $RANDOM should return a random number and use modulo operator
to get the range you want, in this case add 1 after so that the minimum
value is one. A counter can be maintained and incremented each loop
(I've used 'expr' here for maths but it's probably more likely that
you'll want to use '$((' because that arithmetic evaluation is builtin
to the shell). Just check the counter until it gets to the maximum
value using a while loop ('for' loop in UNIX shell is very different
to the C version).
#!/bin/sh
COUNT=$1 # set maximum value for loop count from command line parameter $1
i=0 # $i counts the number of loops so far
while [ $i -ne $COUNT ] # repeat until we get to the maximum count
do
a=`expr $RANDOM % 65536 + 1` # set $a to a random number s.t 1<=$a<=65536
program $a # invoke program with $a as argument 1
i=`expr $i + 1` # increment loop count by 1
done
(untested)
I recommend that you read your shell man page (man sh), all the
important building blocks of shell command language are well
documented in there and it pays to read it through (even a couple
of times over :)
ByeFrom
--
: ${L} # http://lf.8k.com:80