select a number < 8 return a randle number that <= 7

/**
  select a number < 8 

  return a randle number that <= 7
*/
int selrand()
{
        int iSecret, iGuess;
        bool iselect = true;
        static vector< int > selected;
        static vector< int >::iterator itsel;

        /* initialize random seed: */
        srand( time( NULL ) );

        /* generate secret number: */
        do
        {
               iSecret = rand() % 8;
                                        
                itsel = find( selected.begin(), selected.end(), iSecret );
                if ( itsel == selected.end() )
                {
                        selected.push_back( iSecret );
                        iselect = false;
                }               
                
        } while ( iselect );
        
        return iSecret; 
posted @ 2011-03-12 12:53  lxgeek  阅读(230)  评论(0编辑  收藏  举报