From 985f7bfea070a1b10dff7461c811f540a7659e89 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 19 Jun 2013 07:27:34 -0700 Subject: [PATCH] tweak: don't restart whole loop on unlikely random result --- xwords4/relay/dbmgr.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xwords4/relay/dbmgr.cpp b/xwords4/relay/dbmgr.cpp index b88c68b91..e205484ec 100644 --- a/xwords4/relay/dbmgr.cpp +++ b/xwords4/relay/dbmgr.cpp @@ -324,10 +324,10 @@ DBMgr::RegisterDevice( const DevID* host ) for ( success = false, ii = 0; !success; ++ii ) { assert( 10 > ii ); // better to check that we're looping BECAUSE // of uniqueness problem. - devID = (DevIDRelay)random(); - if ( DEVID_NONE == devID ) { - continue; - } + do { + devID = (DevIDRelay)random(); + } while ( DEVID_NONE != devID ); + const char* command = "INSERT INTO " DEVICES_TABLE " (id, devType, devid)" " VALUES( $1, $2, $3 )";