[Freeswitch-users] Random number generation

Chris Young Chris.Young at enghouse.com
Tue Jan 24 12:52:52 MSK 2017


Hi Srigo,

Thanks for your help. Unfortunately, I still see the same value getting generated each time the extension gets executed e.g.

                51a7a226-27e6-4fe3-979b-0b0bb28253d9 2017-01-24 09:49:21.504783 [INFO] mod_dptools.c:1628 Random value is 1
70aae2dc-cee6-4a3c-805f-5655abd7e6e6 2017-01-24 09:49:21.965642 [INFO] mod_dptools.c:1628 Random value is 1
92e81c00-0ff0-4ddc-819f-019c145f39be 2017-01-24 09:49:22.444287 [INFO] mod_dptools.c:1628 Random value is 1

I take it that from-core is some context you've defined in your environment rather than anything special, as it didn't work when I used that (so I changed it to 'default')?

Regards,
Chris


From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of KSrigo
Sent: 24 January 2017 09:14
To: FreeSWITCH Users Help <freeswitch-users at lists.freeswitch.org>
Subject: Re: [Freeswitch-users] Random number generation

Hi Chris,

I’m not sure if I understood exactly your needs. This is how I use randomize function:

Define Random Number Generator extension:

<extension name="random_number_gen" continue="true">
  <condition field="destination_number" expression="^random_number_gen$" break="never">
    <!-- generate random number between 1 and 100 -->
    <action application="set" data="rand_val=${expr(randomize(&x);ceil(random(0,100,&x)))}" inline="true"/>
    <action application="log" data="INFO Random value is ${rand_val}"/>
  </condition>
</extension>


then call it in your diaplan each time you need to get a random number set:

<action application="execute_extension" data="random_number_gen XML from-core"/>


Regards,
Srigo


On Jan 24, 2017, at 9:51 AM, Chris Young <Chris.Young at enghouse.com<mailto:Chris.Young at enghouse.com>> wrote:

Hello all,

On the wiki, there is an example of using mod_expr to generate a random number:

                <!-- generate random number between 1 and 100 -->
                <action application="set" data="rand_val=${expr(randomize(&x);ceil(random(0,100,&x)))}"/>
                <action application="log" data="INFO Random value is ${rand_val}"/>

This works well the first time but if the same dialplan instructions are executed subsequently, the same number is produced each time.

Is this by design? Is there any other way to seed the random number generator so it will produce different results, as randomize() doesn't seem to be doing quite what I thought it would?

Many thanks,
Chris

Chris Young
Software Engineer
<image001.png>
t:  +44 118 943 9249
e:  chris.young at enghouse.com<mailto:chris.young at enghouse.com>
w: www.enghouseinteractive.co.uk<http://www.enghouseinteractive.co.uk/>
<image002.png>
Enghouse Interactive (UK) Ltd is a company registered in England and Wales. Registered number: 04230977. Registered office: Imperium, Imperial Way, Reading, Berkshire, RG2 0TD

_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting at freeswitch.org<mailto:consulting at freeswitch.org>
http://www.freeswitchsolutions.com<http://www.freeswitchsolutions.com/>

Official FreeSWITCH Sites
http://www.freeswitch.org<http://www.freeswitch.org/>
http://confluence.freeswitch.org<http://confluence.freeswitch.org/>
http://www.cluecon.com<http://www.cluecon.com/>

FreeSWITCH-users mailing list
FreeSWITCH-users at lists.freeswitch.org<mailto:FreeSWITCH-users at lists.freeswitch.org>
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users<http://lists.freeswitch.org/mailman/options/freeswitch-users>
http://www.freeswitch.org<http://www.freeswitch.org/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20170124/ca353bb1/attachment-0001.html 


Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users mailing list