Re: [exim] lsearch and random numbers

Top Page
Delete this message
Reply to this message
Author: Ben Allen
Date:  
To: exim-users
Subject: Re: [exim] lsearch and random numbers
On Friday, November 26, 2010 12:56:31 am Jozeph Brasil .'. wrote:

> How to make exim 'exec' that expression on lsearch result to return a
> numeric value (192.168.0.N)?
>
> How to generate a random number from a range? For example, I need to
> generate random numbers from 30 to 112, is it possible?
>


Something like:
    ${eval:${randint:${eval:112+1-30}}+30}
will get you a random number between 30 and 112. You will need the 112+1 part 
or you'll get a range between 30 and 119.This will only work on up to date 
Exim versions. Not sure when randint got added, but it's not in 4.63, and is 
in 4.71.


If you're using an old build (e.g. the stock Redhat 4.63), then I guess you'll 
have to get a random number from the OS. E.g.
    ${eval:${run{/bin/bash -c 'echo -n \$RANDOM'}}%(112+1-30)+30}
It won't be a perfect distribution over the range (since $RANDOM goes 0 to 
32767 in bash, and the modulus will therefore skew it a bit), but will be good 
enough for what you want.


Regards

Ben