--- branches/1.4/main/manager.c	2008/01/17 23:23:25	99010
+++ branches/1.4/main/manager.c	2008/02/27 18:15:10	104704
@@ -2660,7 +2660,12 @@
 		ast_mutex_init(&s->__lock);
 		ast_mutex_lock(&s->__lock);
 		s->inuse = 1;
-		s->managerid = rand() | (unsigned long)s;
+		/*!\note There is approximately a 1 in 1.8E19 chance that the following
+		 * calculation will produce 0, which is an invalid ID, but due to the
+		 * properties of the rand() function (and the constantcy of s), that
+		 * won't happen twice in a row.
+		 */
+		while ((s->managerid = rand() ^ (unsigned long) s) == 0);
 		AST_LIST_LOCK(&sessions);
 		AST_LIST_INSERT_HEAD(&sessions, s, list);
 		/* Hook into the last spot in the event queue */
