Can someone do me a favour and explain the following for me:
((r=$RANDOM%$n+1))
I know what $RANDOM does but what is % sign and what does it do with %$n+1?
Can someone do me a favour and explain the following for me:
((r=$RANDOM%$n+1))
I know what $RANDOM does but what is % sign and what does it do with %$n+1?
Correct syntax:
$((r=$RANDOM%$n+1))
That generates a random number between 1 and the value of n. % is the modulo arithmetic operator - the remainder of division.
Actually this is correct syntax in bash/ksh. It can also be written as:
((r=RANDOM%n+1))