It's very strange. Anyway, thank you for trying and for confirming my dialplan. Out of interest, which platform are you running FreeSWITCH on? From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of KSrigo Sent: 24 January 2017 13:26 To: FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Random number generation Then I have no idea why it’s not working for you. I even tried your dialplan its working fine: Dialplan: <!--TEST START--> <extension name="call_duration" continue="true"> <condition field="destination_number" expression="^call_duration$" break="never"> <action application="set" data="call_length=${expr(randomize(&x);ceil(random(29999,45000,&x)))}" inline="true"/> <action application="log" data="INFO Random value is ${call_length}"/> </condition> </extension> <extension name="transfer_request"> <condition field="destination_number" expression="^\*(85)$"> <action application="pre_answer"/> <action application="answer"/> <action application="execute_extension" data="call_duration XML from-core"/> <action application="log" data="INFO Call from ${caller_id_number} to ${destination_number} will last for ${call_length}ms"/> <action application="execute_extension" data="call_duration XML from-core"/> <action application="log" data="INFO Call from ${caller_id_number} to ${destination_number} will last for ${call_length}ms"/> <action application="sleep" data="${call_length}"/> <action application="hangup" data="NORMAL_CLEARING"/> </condition> </extension> <!--TEST END--> Output: 2017-01-24 13:22:23.616006 [INFO] mod_dialplan_xml.c:637 Processing 33170567631 <33170567631>->call_duration in context from-core Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->unloop] continue=false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (PASS) [unloop] ${unroll_loops}(true) =~ /^true$/ break=on-false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (FAIL) [unloop] ${sip_looped_call}() =~ /^true$/ break=on-false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->outside_call] continue=true Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Absolute Condition [outside_call] Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Action set(outside_call=true) Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Action export(RFC2822_DATE=${strftime(%a, %d %b %Y %T %z)}) Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->call_duration] continue=true Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (PASS) [call_duration] destination_number(call_duration) =~ /^call_duration$/ break=never Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Action set(call_length=${expr(randomize(&x);ceil(random(29999,45000,&x)))}) INLINE EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> set(call_length=35719) 2017-01-24 13:22:23.616006 [DEBUG] mod_dptools.c:1519 SET sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> [call_length]=[35719] Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Action log(INFO Random value is ${call_length}) Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->transfer_request] continue=false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (FAIL) [transfer_request] destination_number(call_duration) =~ /^\*(85)$/ break=on-false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->call_debug] continue=true Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (FAIL) [call_debug] ${call_debug}(false) =~ /^true$/ break=never Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->homer_X_cid] continue=true Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (PASS) [homer_X_cid] destination_number(call_duration) =~ /.*/ break=on-false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Action set(sip_h_X-CID=${sip_call_id}) Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->Local_Extension] continue=false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (FAIL) [Local_Extension] destination_number(call_duration) =~ /^\*(85)$/ break=on-false 2017-01-24 13:22:23.616006 [NOTICE] switch_core_session.c:2895 Execute set(outside_call=true) EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> set(outside_call=true) 2017-01-24 13:22:23.616006 [DEBUG] mod_dptools.c:1519 SET sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> [outside_call]=[true] 2017-01-24 13:22:23.616006 [NOTICE] switch_core_session.c:2895 Execute export(RFC2822_DATE=${strftime(%a, %d %b %Y %T %z)}) EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> export(RFC2822_DATE=Tue, 24 Jan 2017 13:22:23 +0000) 2017-01-24 13:22:23.616006 [DEBUG] switch_channel.c:1296 EXPORT (export_vars) [RFC2822_DATE]=[Tue, 24 Jan 2017 13:22:23 +0000] 2017-01-24 13:22:23.616006 [NOTICE] switch_core_session.c:2895 Execute log(INFO Random value is ${call_length}) EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> log(INFO Random value is 35719) 2017-01-24 13:22:23.616006 [INFO] mod_dptools.c:1713 Random value is 35719 2017-01-24 13:22:23.616006 [NOTICE] switch_core_session.c:2895 Execute set(sip_h_X-CID=${sip_call_id}) EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> set(sip_h_X-CID=313438353236343134333135383733-7sj1k4kl0i83) 2017-01-24 13:22:23.616006 [DEBUG] mod_dptools.c:1519 SET sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> [sip_h_X-CID]=[313438353236343134333135383733-7sj1k4kl0i83] EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> log(INFO Call from 33170567631 to *85 will last for 35719ms) 2017-01-24 13:22:23.616006 [INFO] mod_dptools.c:1713 Call from 33170567631 to *85 will last for 35719ms EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> execute_extension(call_duration XML from-core) 2017-01-24 13:22:23.616006 [INFO] mod_dialplan_xml.c:637 Processing 33170567631 <33170567631>->call_duration in context from-core Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->unloop] continue=false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (PASS) [unloop] ${unroll_loops}(true) =~ /^true$/ break=on-false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (FAIL) [unloop] ${sip_looped_call}() =~ /^true$/ break=on-false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->outside_call] continue=true Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Absolute Condition [outside_call] Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Action set(outside_call=true) Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Action export(RFC2822_DATE=${strftime(%a, %d %b %Y %T %z)}) Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->call_duration] continue=true Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (PASS) [call_duration] destination_number(call_duration) =~ /^call_duration$/ break=never Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Action set(call_length=${expr(randomize(&x);ceil(random(29999,45000,&x)))}) INLINE EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> set(call_length=33576) 2017-01-24 13:22:23.616006 [DEBUG] mod_dptools.c:1519 SET sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> [call_length]=[33576] Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Action log(INFO Random value is ${call_length}) Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->transfer_request] continue=false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (FAIL) [transfer_request] destination_number(call_duration) =~ /^\*(85)$/ break=on-false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->call_debug] continue=true Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (FAIL) [call_debug] ${call_debug}(false) =~ /^true$/ break=never Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->homer_X_cid] continue=true Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (PASS) [homer_X_cid] destination_number(call_duration) =~ /.*/ break=on-false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Action set(sip_h_X-CID=${sip_call_id}) Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> parsing [from-core->Local_Extension] continue=false Dialplan: sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> Regex (FAIL) [Local_Extension] destination_number(call_duration) =~ /^\*(85)$/ break=on-false 2017-01-24 13:22:23.616006 [NOTICE] switch_core_session.c:2895 Execute set(outside_call=true) EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> set(outside_call=true) 2017-01-24 13:22:23.616006 [DEBUG] mod_dptools.c:1519 SET sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> [outside_call]=[true] 2017-01-24 13:22:23.616006 [NOTICE] switch_core_session.c:2895 Execute export(RFC2822_DATE=${strftime(%a, %d %b %Y %T %z)}) EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> export(RFC2822_DATE=Tue, 24 Jan 2017 13:22:23 +0000) 2017-01-24 13:22:23.616006 [DEBUG] switch_channel.c:1296 EXPORT (export_vars) [RFC2822_DATE]=[Tue, 24 Jan 2017 13:22:23 +0000] 2017-01-24 13:22:23.616006 [NOTICE] switch_core_session.c:2895 Execute log(INFO Random value is ${call_length}) EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> log(INFO Random value is 33576) 2017-01-24 13:22:23.616006 [INFO] mod_dptools.c:1713 Random value is 33576 2017-01-24 13:22:23.616006 [NOTICE] switch_core_session.c:2895 Execute set(sip_h_X-CID=${sip_call_id}) EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> set(sip_h_X-CID=313438353236343134333135383733-7sj1k4kl0i83) 2017-01-24 13:22:23.616006 [DEBUG] mod_dptools.c:1519 SET sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> [sip_h_X-CID]=[313438353236343134333135383733-7sj1k4kl0i83] EXECUTE sofia/core/33170567631@sip.v.ibrowse.com<mailto:sofia/core/33170567631@sip.v.ibrowse.com> log(INFO Call from 33170567631 to *85 will last for 33576ms) 2017-01-24 13:22:23.616006 [INFO] mod_dptools.c:1713 Call from 33170567631 to *85 will last for 33576ms regards, srigo On Jan 24, 2017, at 2:00 PM, Chris Young <Chris.Young@enghouse.com<mailto:Chris.Young@enghouse.com>> wrote: I was running an older version of FreeSWITCH (1.5.15) but I've just retried with 1.6.14 and I still get the same behaviour. I am running on Windows in case that makes any difference. Here is my dialplan. This server is part of a test environment and what I am trying to achieve is to have a variable call duration: <?xml version="1.0" encoding="utf-8"?> <include> <extension name="persistent_agent_leg"> <condition field="destination_number" expression="^([78]\d{3})$"> <action application="set" data="send_silence_when_idle=400"/> <action application="pre_answer"/> <action application="answer"/> <action application="park"/> </condition> </extension> <extension name="call_duration" continue="true"> <condition field="destination_number" expression="^call_duration$" break="never"> <action application="set" data="call_length=${expr(randomize(&x);ceil(random(29999,45000,&x)))}" inline="true"/> </condition> </extension> <extension name="transfer_request"> <condition field="destination_number" expression="^([45]\d{3})$"> <action application="pre_answer"/> <action application="answer"/> <action application="execute_extension" data="call_duration XML default"/> <action application="log" data="INFO Call from ${caller_id_number} to ${destination_number} will last for ${call_length}ms"/> <action application="sleep" data="${call_length}"/> <action application="hangup" data="NORMAL_CLEARING"/> </condition> </extension> </include> From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of KSrigo Sent: 24 January 2017 10:37 To: FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org>> Subject: Re: [Freeswitch-users] Random number generation Yes “from-core" was my context for the test. You have to update according your config. Could you tell me your freeswitch version? Mine is: FreeSWITCH Version 1.6.8-15-99de0ad~64bit. The config I gave you works fine on it. Could you post your dialplan ? Here is the whole dial plan I used for the test: <include> <context name="from-core"> <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> <extension name="Local_Extension"> <condition field="destination_number" expression="^\*(85)$"> <!--test 1--> <action application="execute_extension" data="random_number_gen XML from-core"/> <!--test 2--> <action application="execute_extension" data="random_number_gen XML from-core"/> <action application="hangup"/> </condition> </extension> </context> <include> Regards, Srigo On Jan 24, 2017, at 10:52 AM, Chris Young <Chris.Young@enghouse.com<mailto:Chris.Young@enghouse.com>> wrote: 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@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of KSrigo Sent: 24 January 2017 09:14 To: FreeSWITCH Users Help <freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@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@enghouse.com<mailto:Chris.Young@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@enghouse.com<mailto:chris.young@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@freeswitch.org<mailto:consulting@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@lists.freeswitch.org<mailto:FreeSWITCH-users@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/> _________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org<mailto:consulting@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@lists.freeswitch.org<mailto:FreeSWITCH-users@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/> _________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org<mailto:consulting@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@lists.freeswitch.org<mailto:FreeSWITCH-users@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/>