Click here to Skip to main content
15,886,780 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionClose X button in tadded control and vertical scroll. Pin
birajendu24-Jun-09 2:46
birajendu24-Jun-09 2:46 
Questionerror C2664 in VS2005 VC++ Pin
Nandu_77b24-Jun-09 2:01
Nandu_77b24-Jun-09 2:01 
AnswerRe: error C2664 in VS2005 VC++ Pin
Cedric Moonen24-Jun-09 2:03
Cedric Moonen24-Jun-09 2:03 
QuestionOpening multiple dialogs Pin
FISH78624-Jun-09 1:51
FISH78624-Jun-09 1:51 
AnswerRe: Opening multiple dialogs Pin
Cedric Moonen24-Jun-09 2:00
Cedric Moonen24-Jun-09 2:00 
GeneralRe: Opening multiple dialogs Pin
FISH78624-Jun-09 2:10
FISH78624-Jun-09 2:10 
AnswerRe: Opening multiple dialogs Pin
_AnsHUMAN_ 24-Jun-09 2:57
_AnsHUMAN_ 24-Jun-09 2:57 
Questionrandom numbers - the old bugger ... Pin
Souldrift24-Jun-09 1:02
Souldrift24-Jun-09 1:02 
Hey good people,

I am in need of an idea for a problem that has to have been solved a throusand times over. But after implementing some code that should take care of the troublemaker (rand()) - but didn´t - and a lot of research I am at a loss here.

I built a server which has to generate some random numbers for each client that connects. So I created a nice singleton wrapper class for the random generator and now it´s seeded (srand(time(NULL))) once at startup and thereafter every call should present me an actual (pseudo-)random number.
As you may have guessed, theory didn´t work out. All numbers are very random for every single call from ONE client. As soon as another client connects it gets THE SAME 'random' sequence of numbers. Even though the seed was plantet only once AND they don´t even ask at the same time.

Here´s a little code on the number generation, maybe someone has an idea:

ToolBox* ToolBox::m_pToolbox = NULL;

ToolBox::ToolBox(void)
{
	m_pLogger = Logger::GetInstance();
	srand ( time(NULL) );
}

ToolBox::~ToolBox(void)
{
}

ToolBox* ToolBox::GetInstance()
{
	if( m_pToolbox == NULL )
	{
		m_pToolbox = new ToolBox();
	}
	return m_pToolbox;
}

///////////////////////////////////////////////////////////////////////////////////
//		Random number generation
///////////////////////////////////////////////////////////////////////////////////

//
BYTE ToolBox::GenerateRandomByte()
{
	BYTE ret = LOBYTE((WORD)rand());

        // test random numbers
	int r1 = rand();
	int r2 = rand();
	int r3 = rand();
	int r4 = rand();
	m_pLogger->Out( Logger::DEBUG, "TestRand 1: %d\nTestRand 2: %d\nTestRand 3: %d\nTestRand 4: %d\n", r1, r2, r3, r4 );

	return ret;	
}

int ToolBox::GenerateRandomInt()
{
	return rand();
}


Any help is appreciated. Thanks.

Souldrift
AnswerRe: random numbers - the old bugger ... Pin
Michael Schubert24-Jun-09 1:31
Michael Schubert24-Jun-09 1:31 
GeneralRe: random numbers - the old bugger ... Pin
Souldrift24-Jun-09 2:29
Souldrift24-Jun-09 2:29 
AnswerRe: random numbers - the old bugger ... [modified] Pin
CPallini24-Jun-09 1:40
mveCPallini24-Jun-09 1:40 
GeneralRe: random numbers - the old bugger ... Pin
Souldrift24-Jun-09 2:29
Souldrift24-Jun-09 2:29 
QuestionRe: random numbers - the old bugger ... Pin
CPallini24-Jun-09 2:49
mveCPallini24-Jun-09 2:49 
AnswerRe: random numbers - the old bugger ... Pin
Souldrift24-Jun-09 3:06
Souldrift24-Jun-09 3:06 
AnswerRe: random numbers - the old bugger ... Pin
Stuart Dootson24-Jun-09 3:00
professionalStuart Dootson24-Jun-09 3:00 
GeneralRe: random numbers - the old bugger ... Pin
Souldrift24-Jun-09 3:12
Souldrift24-Jun-09 3:12 
GeneralRe: random numbers - the old bugger ... Pin
Stuart Dootson24-Jun-09 3:23
professionalStuart Dootson24-Jun-09 3:23 
GeneralRe: random numbers - the old bugger ... Pin
Souldrift24-Jun-09 3:29
Souldrift24-Jun-09 3:29 
QuestionNeed a help regarding crystal report Pin
tasumisra23-Jun-09 23:42
tasumisra23-Jun-09 23:42 
AnswerRe: Need a help regarding crystal report Pin
Rajesh R Subramanian24-Jun-09 1:18
professionalRajesh R Subramanian24-Jun-09 1:18 
GeneralRe: Need a help regarding crystal report Pin
tasumisra24-Jun-09 2:30
tasumisra24-Jun-09 2:30 
Questioncalling java dll from MFC Pin
sunnyram23-Jun-09 22:24
sunnyram23-Jun-09 22:24 
AnswerRe: calling java dll from MFC Pin
Stuart Dootson23-Jun-09 23:07
professionalStuart Dootson23-Jun-09 23:07 
AnswerRe: calling java dll from MFC Pin
CPallini23-Jun-09 23:11
mveCPallini23-Jun-09 23:11 
AnswerRe: calling java dll from MFC Pin
KarstenK24-Jun-09 2:37
mveKarstenK24-Jun-09 2:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.