Upgrade 3CX to v18 and get it hosted free!

Asterisk func rand

Author image

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


Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.