[SR-Users] Random number generation kamailio

Daniel-Constantin Mierla miconda at gmail.com
Wed Mar 23 12:19:54 CET 2016


The $random gives an integer value, so max length is 10. Actually, vars
in config file can be either integer or string. If you want a larger
length you can build it as tring from two other random values. Like:

$var(r1) = $RANDOM;
$var(r2) = $RANDOM;

$var(largerandom) = "" + $var(r1) + $var(r2);

Note the empty string "" used as first element in the right side of the
above assignment -- that will make the result to be string, otherwise
will be another int, rounded after overflow.

To get string from concatenating two integers you can use alternatives
as pv_printf(...) or $_s(...).

Cheers,
Daniel


On 23/03/16 11:03, Cibin Paul wrote:
> Daniel,
>
> I tried using $RANDOM. It is always giving a random value between 9
> digits to 10 digits  How can I get a random value between 10 digits to
> 13 digits. 
>
> Regards
> Cibin
>
>
>
>> On 22-Mar-2016, at 1:19 PM, Cibin Paul <paul_cibin at me.com
>> <mailto:paul_cibin at me.com>> wrote:
>>
>> Thanks Daniel for the pointer. I will check both modules
>>
>> Regards
>> Cibin
>>
>>
>>
>>
>>
>>> On 22-Mar-2016, at 1:13 PM, Daniel-Constantin Mierla
>>> <miconda at gmail.com <mailto:miconda at gmail.com>> wrote:
>>>
>>>
>>>
>>> On 22/03/16 08:40, Cibin Paul wrote:
>>>> Thanks Daniel,
>>>>
>>>> I will try app_lua as you said this being faster compared to $RANDOM.
>>> I didn't say that app_lua is faster than $RANDOM -- what I said is that
>>> app_lua is also fast.
>>>
>>>>
>>>> Now if I want to modify the caller id number (ANI) , can I assign
>>>> the newly generated number to the variable $fU?
>>>
>>> Yes, look also at uac module for functions to replace From URI.
>>>
>>> Cheers,
>>> Daniel
>>>>
>>>> Regards
>>>> Cibin
>>>>
>>>>
>>>>
>>>>> On 22-Mar-2016, at 12:50 PM, Daniel-Constantin Mierla
>>>>> <miconda at gmail.com <mailto:miconda at gmail.com>> wrote:
>>>>>
>>>>> Hello,
>>>>>
>>>>> besides $RANDOM from cfgutils as pointed already, you can use an
>>>>> embedded interpreter (e.g., app_lua is really fast).
>>>>>
>>>>> If you need some unique values, but not only numbers, see uuid module.
>>>>>
>>>>> Cheers,
>>>>> Daniel
>>>>>
>>>>> On 22/03/16 07:54, Cibin Paul wrote:
>>>>>> Hi,
>>>>>>
>>>>>> How can I generate a random number say of length 10-14 in
>>>>>> Kamailio. Can I use cfgutils for this. Please advise
>>>>>>
>>>>>> Regards
>>>>>> Cibin
>>>>>>
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users
>>>>>> mailing list
>>>>>> sr-users at lists.sip-router.org <mailto:sr-users at lists.sip-router.org>
>>>>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
>>>>> -- 
>>>>> Daniel-Constantin Mierla
>>>>> http://www.asipto.com <http://www.asipto.com/>
>>>>> http://twitter.com/#!/miconda <http://twitter.com/#%21/miconda> -
>>>>> http://www.linkedin.com/in/miconda
>>>>> Kamailio World Conference, Berlin, May 18-20, 2016 -
>>>>> http://www.kamailioworld.com
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing
>>>>> list
>>>>> sr-users at lists.sip-router.org <mailto:sr-users at lists.sip-router.org>
>>>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
>>>
>>> -- 
>>> Daniel-Constantin Mierla
>>> http://www.asipto.com <http://www.asipto.com/>
>>> http://twitter.com/#!/miconda
>>> <http://twitter.com/#%21/miconda> - http://www.linkedin.com/in/miconda
>>> Kamailio World Conference, Berlin, May 18-20, 2016
>>> - http://www.kamailioworld.com <http://www.kamailioworld.com/>
>>
>

-- 
Daniel-Constantin Mierla
http://www.asipto.com
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Kamailio World Conference, Berlin, May 18-20, 2016 - http://www.kamailioworld.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20160323/68b04903/attachment.html>


More information about the sr-users mailing list