# RAND : Asterisk function to choose a random number

## RAND : Asterisk function to choose a random number

rand function is use to choose a random number in a range.  Range has to be set between minimum and maximum number. This would be useful in many scenario based on implementation logic. some of the examples are :

### Check if RAND function is available

CLI> core show function RAND

### How to use RAND function

`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).

## What this function returns

RAND function return a single random number from minimum and maximum range.

`exten => s,1,Set(satya=\${RAND(1,10)})`

`; - Sets a value of a variable to a random number between 1 and 10.`

### Example to use random outbound trunk

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)`

how to set random caller ids on Asterisk based system