Asterisk func rand

Synopsis:

Choose a random number in a range

Description:

  RAND([min][,max])


Choose a random number between min and max. Min defaults to 0, if not
specified, while max defaults to RAND_MAX (2147483647 on many systems).


Notes


  • *CLI> core show function RAND

  • This functions is only availible in 1.4 and later.

Return value

Returns the resulting number.

Example1

 exten => s,1,Set(junky=${RAND(1,8)});
     - Sets junky to a random number between 1 and 8, inclusive.


Example2

if we had few caller ID number want to use it, try this:

[outbound]
exten => _886X.,1,Noop
  same => n,Gosub(pickCallerIDnum,cell${RAND(1,5)},1)
  same => n,Dial(SIP/${EXTEN}@gateway,32,gCX)

[pickCallerIDnum]
exten => cell1,1,Set(CALLERID(num)=09xxxxxxx1)
  same => n,Return
exten => cell2,1,Set(CALLERID(num)=09xxxxxxx2)
  same => n,Return
exten => cell3,1,Set(CALLERID(num)=09xxxxxxx3)
  same => n,Return
exten => cell4,1,Set(CALLERID(num)=09xxxxxxx4)
  same => n,Return
exten => cell5,1,Set(CALLERID(num)=09xxxxxxx5)
  same => n,Return


Example3

if we had 5 outbound gateway, we wanna use it equally, try this:

exten => _09XXXXXXXX,1,Set(VOLUME(RX)=5)
  same => 2,Goto(${RAND(3,7)})
  ;set priority number from 3~7 random
  same=> 3,Dial(SIP/${EXTEN}@gateway0)
  same=> 4,Dial(SIP/${EXTEN}@gateway1)
  same=> 5,Dial(SIP/${EXTEN}@gateway2)
  same=> 6,Dial(SIP/${EXTEN}@gateway3)
  same=> 7,Dial(SIP/${EXTEN}@gateway4)


See also


Synopsis:

Choose a random number in a range

Description:

  RAND([min][,max])


Choose a random number between min and max. Min defaults to 0, if not
specified, while max defaults to RAND_MAX (2147483647 on many systems).


Notes


  • *CLI> core show function RAND

  • This functions is only availible in 1.4 and later.

Return value

Returns the resulting number.

Example1

 exten => s,1,Set(junky=${RAND(1,8)});
     - Sets junky to a random number between 1 and 8, inclusive.


Example2

if we had few caller ID number want to use it, try this:

[outbound]
exten => _886X.,1,Noop
  same => n,Gosub(pickCallerIDnum,cell${RAND(1,5)},1)
  same => n,Dial(SIP/${EXTEN}@gateway,32,gCX)

[pickCallerIDnum]
exten => cell1,1,Set(CALLERID(num)=09xxxxxxx1)
  same => n,Return
exten => cell2,1,Set(CALLERID(num)=09xxxxxxx2)
  same => n,Return
exten => cell3,1,Set(CALLERID(num)=09xxxxxxx3)
  same => n,Return
exten => cell4,1,Set(CALLERID(num)=09xxxxxxx4)
  same => n,Return
exten => cell5,1,Set(CALLERID(num)=09xxxxxxx5)
  same => n,Return


Example3

if we had 5 outbound gateway, we wanna use it equally, try this:

exten => _09XXXXXXXX,1,Set(VOLUME(RX)=5)
  same => 2,Goto(${RAND(3,7)})
  ;set priority number from 3~7 random
  same=> 3,Dial(SIP/${EXTEN}@gateway0)
  same=> 4,Dial(SIP/${EXTEN}@gateway1)
  same=> 5,Dial(SIP/${EXTEN}@gateway2)
  same=> 6,Dial(SIP/${EXTEN}@gateway3)
  same=> 7,Dial(SIP/${EXTEN}@gateway4)


See also


Created by: murf, Last modification: Wed 09 of Jan, 2013 (09:34 UTC) by dominic16y
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+