Index: /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
===================================================================
--- /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 4956)
+++ /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 4957)
@@ -3293,6 +3293,7 @@
      * occurs because of transport failure, the first retry will be done
      * after \a reg_first_retry_interval seconds instead. Also note that
-     * the interval will be randomized slightly by approximately +/- ten
-     * seconds to avoid all clients re-registering at the same time.
+     * the interval will be randomized slightly by some seconds (specified
+     * in \a reg_retry_random_interval) to avoid all clients re-registering
+     * at the same time.
      *
      * See also \a reg_first_retry_interval setting.
@@ -3305,9 +3306,24 @@
      * This specifies the interval for the first registration retry. The
      * registration retry is explained in \a reg_retry_interval. Note that
-     * the value here will also be randomized by +/- ten seconds.
+     * the value here will also be randomized by some seconds (specified
+     * in \a reg_retry_random_interval) to avoid all clients re-registering
+     * at the same time.
      *
      * Default: 0
      */
     unsigned	     reg_first_retry_interval;
+
+    /**
+     * This specifies maximum randomized value to be added/substracted
+     * to/from the registration retry interval specified in \a
+     * reg_retry_interval and \a reg_first_retry_interval, in second.
+     * This is useful to avoid all clients re-registering at the same time.
+     * For example, if the registration retry interval is set to 100 seconds
+     * and this is set to 10 seconds, the actual registration retry interval
+     * will be in the range of 90 to 110 seconds.
+     *
+     * Default: 10
+     */
+    unsigned	     reg_retry_random_interval;
 
     /**
Index: /pjproject/trunk/pjsip/include/pjsua2/account.hpp
===================================================================
--- /pjproject/trunk/pjsip/include/pjsua2/account.hpp	(revision 4956)
+++ /pjproject/trunk/pjsip/include/pjsua2/account.hpp	(revision 4957)
@@ -82,8 +82,10 @@
      * occurs because of transport failure, the first retry will be done
      * after \a firstRetryIntervalSec seconds instead. Also note that
-     * the interval will be randomized slightly by approximately +/- ten
-     * seconds to avoid all clients re-registering at the same time.
-     *
-     * See also \a firstRetryIntervalSec setting.
+     * the interval will be randomized slightly by some seconds (specified
+     * in \a reg_retry_random_interval) to avoid all clients re-registering
+     * at the same time.
+     *
+     * See also \a firstRetryIntervalSec and \a randomRetryIntervalSec
+     * settings.
      *
      * Default: PJSUA_REG_RETRY_INTERVAL
@@ -94,9 +96,28 @@
      * This specifies the interval for the first registration retry. The
      * registration retry is explained in \a retryIntervalSec. Note that
-     * the value here will also be randomized by +/- ten seconds.
+     * the value here will also be randomized by some seconds (specified
+     * in \a reg_retry_random_interval) to avoid all clients re-registering
+     * at the same time.
+     *
+     * See also \a retryIntervalSec and \a randomRetryIntervalSec settings.
      *
      * Default: 0
      */
     unsigned		firstRetryIntervalSec;
+
+    /**
+     * This specifies maximum randomized value to be added/substracted
+     * to/from the registration retry interval specified in \a
+     * reg_retry_interval and \a reg_first_retry_interval, in second.
+     * This is useful to avoid all clients re-registering at the same time.
+     * For example, if the registration retry interval is set to 100 seconds
+     * and this is set to 10 seconds, the actual registration retry interval
+     * will be in the range of 90 to 110 seconds.
+     *
+     * See also \a retryIntervalSec and \a firstRetryIntervalSec settings.
+     *
+     * Default: 10
+     */
+    unsigned		randomRetryIntervalSec;
 
     /**
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 4956)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 4957)
@@ -1205,4 +1205,5 @@
     acc->cfg.reg_retry_interval = cfg->reg_retry_interval;
     acc->cfg.reg_first_retry_interval = cfg->reg_first_retry_interval;
+    acc->cfg.reg_retry_random_interval = cfg->reg_retry_random_interval;    
     acc->cfg.drop_calls_on_reg_fail = cfg->drop_calls_on_reg_fail;
     acc->cfg.register_on_acc_add = cfg->register_on_acc_add;
@@ -3540,10 +3541,13 @@
     delay.msec = 0;
 
-    /* Randomize interval by +/- 10 secs */
-    if (delay.sec >= 10) {
-	delay.msec = -10000 + (pj_rand() % 20000);
-    } else {
-	delay.sec = 0;
-	delay.msec = (pj_rand() % 10000);
+    /* Randomize interval by +/- reg_retry_random_interval, if configured */
+    if (acc->cfg.reg_retry_random_interval) {
+	long rand_ms = acc->cfg.reg_retry_random_interval * 1000;
+	if (delay.sec >= (long)acc->cfg.reg_retry_random_interval) {
+	    delay.msec = -rand_ms + (pj_rand() % (rand_ms * 2));
+	} else {
+	    delay.sec = 0;
+	    delay.msec = (pj_rand() % (delay.sec * 1000 + rand_ms));
+	}
     }
     pj_time_val_normalize(&delay);
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 4956)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 4957)
@@ -289,4 +289,5 @@
     cfg->srtp_optional_dup_offer = pjsua_var.ua_cfg.srtp_optional_dup_offer;
     cfg->reg_retry_interval = PJSUA_REG_RETRY_INTERVAL;
+    cfg->reg_retry_random_interval = 10;
     cfg->contact_rewrite_method = PJSUA_CONTACT_REWRITE_METHOD;
     cfg->contact_use_src_port = PJ_TRUE;
Index: /pjproject/trunk/pjsip/src/pjsua2/account.cpp
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua2/account.cpp	(revision 4956)
+++ /pjproject/trunk/pjsip/src/pjsua2/account.cpp	(revision 4957)
@@ -39,4 +39,5 @@
     NODE_READ_UNSIGNED	(this_node, retryIntervalSec);
     NODE_READ_UNSIGNED	(this_node, firstRetryIntervalSec);
+    NODE_READ_UNSIGNED	(this_node, randomRetryIntervalSec);
     NODE_READ_UNSIGNED	(this_node, delayBeforeRefreshSec);
     NODE_READ_BOOL	(this_node, dropCallsOnFail);
@@ -56,4 +57,5 @@
     NODE_WRITE_UNSIGNED	(this_node, retryIntervalSec);
     NODE_WRITE_UNSIGNED	(this_node, firstRetryIntervalSec);
+    NODE_WRITE_UNSIGNED	(this_node, randomRetryIntervalSec);
     NODE_WRITE_UNSIGNED	(this_node, delayBeforeRefreshSec);
     NODE_WRITE_BOOL	(this_node, dropCallsOnFail);
@@ -319,4 +321,5 @@
     ret.reg_retry_interval	= regConfig.retryIntervalSec;
     ret.reg_first_retry_interval= regConfig.firstRetryIntervalSec;
+    ret.reg_retry_random_interval= regConfig.randomRetryIntervalSec;
     ret.reg_delay_before_refresh= regConfig.delayBeforeRefreshSec;
     ret.drop_calls_on_reg_fail	= regConfig.dropCallsOnFail;
@@ -446,4 +449,5 @@
     regConfig.retryIntervalSec	= prm.reg_retry_interval;
     regConfig.firstRetryIntervalSec = prm.reg_first_retry_interval;
+    regConfig.randomRetryIntervalSec = prm.reg_retry_random_interval;
     regConfig.delayBeforeRefreshSec = prm.reg_delay_before_refresh;
     regConfig.dropCallsOnFail	= PJ2BOOL(prm.drop_calls_on_reg_fail);
