|
BobInNJ wrote: Given a seed, two different random number generation algorithms will return different random values.
I know, that's fine.
BobInNJ wrote: Worse yet, all random number generators have the property have after a certain number of random numbers being generated, they repeat themselves.
I know, there's a reason they're called pseudo-random generators.
BobInNJ wrote: The length of this sequence is called the period.
Of course: repetaing patterns have a period.
BobInNJ wrote: Over the years, there has been a fair amount of theory on how to develop a good random number generator. I believe the one that comes with the Microsoft C++ compiler is a good one and it has a very long period. I do not know about the one that comes with the Java compiler except that it almost certainly uses a slightly different algorithm and therefore it will have a different period.
Why a slightly different algorithm should have a different period?
BobInNJ wrote: If you need the same results on both C++ and Java, I strongly recommend that you implement your own random number generator.
That's not a good suggestion. As you probably know, writing a good random generator is not a simple matter. It is better (as suggested by Luc Pattyn) to use some technique to exploit the same number generator code or simply adapt an existing one.
BTW: Bob, did you find a bit irony in my OP, didn't you?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
When I wrote:
write your own random number gennerator
I meant that your application should define one not that you need to come up with your own algorithm
for one. I guess I was not clear about that.
Bob
|
|
|
|
|
Hi Bob,
obviously a state-machine with a finite number of state bits will sooner or later repeat itself.
an N-bit random number generator has a maximum period equal to (2^N)-1 which basically tells you the
internal "counter" has one value that is not generated at all (typically zero).
|
|
|
|
|
Hi,
I am desperated: I want to send a WM_USER message to a CHtmlView but the message handler is never called
In my *.h file I have:
#define WM_HYLGETCONTENT WM_USER + 79
afx_msg LRESULT OnHylGetContent(WPARAM wParam, LPARAM lParam);
In my *cpp file I have:
BEGIN_MESSAGE_MAP(CHyperlexView, CHtmlView)
[...]
ON_MESSAGE(WM_HYLGETCONTENT, OnHylGetContent)
END_MESSAGE_MAP()
[...].
afx_msg LRESULT CHyperlexView::OnHylGetContent(WPARAM wParam, LPARAM lParam)
{
MessageBox("I get called!");
return 1111;
}
But the function is never called
I checked with Spy++: The message is sent successfully to the window but the LRESULT is 0 instead of 1111. The message does not appear too.
What could be the problem here?
I have also checked other values for WM_USER, I get the same result
Thank you,
Niki
|
|
|
|
|
You've probably hit a conflict with another existing message ID.
Use WM_APP instead of WM_USER , the latter is obsolete.
What you really should do is use a registered windows message.
Read more about message management here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
From where your sendmessage(...) has been called
|
|
|
|
|
hiz all,
i have an assignment to write a code in c++ using gui including the code of binary search tree to form a window with three buttons one for pre order and one for inorder and one for post order and when we click on any of these buttons it must show the order (like this site http://nova.umuc.edu/~jarc/idsv/lesson1.html[^])open this link and then click start exercise then u'll see a window...
this what i need to do in c++ ,a program that show such window by using c++...
i wrote the code but i have a problem in gui becuase i don't know anything about it in c++ i'm a beginner in programing and i need help in this code
i appreciate any help you can offer
|
|
|
|
|
first, review all you should have been studying in order to do this assignment.
second, ask question to your teacher, instructors about what you did not understand in "first"
third, write down ON PAPER, how the 3 searches should work, play a game with pen and paper.
fourth, start designing your program, define what data structure you will need, start defining algorithms
fifth, code what you design in "four"
sixth, run what you've coded in "five"
if it works, then, you've learn something.
if it does not work, go back to "first" and/or "second"
if it still does not work, ask a CLEAR, CONSISED and PRECISE question here; and I'm certain we will
be able to help.
|
|
|
|
|
Hi all,
I have IntelliSense:'No additional information available' problem in VC++2005 how can i resolve this.
Help me for this.
thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Do you have this problem on all projects or no and do you have open programs except VS?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
No
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Do you have latest Service pack installed? I found a similar thread[^] which says that its a bug in Visual Studio and the fix will be available in the latest service pack. So try installing the latest VS 2005 service pack from here[^], incase if you don't have it.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Close your project/solution and delete the NCB file associated with your project. Its a binary-tree containing the intelliSense data. Deleting it will force it to be rebuilt the next time you open the project. Hopefully that fixes your issue.
Best Wishes,
-David Delaune
|
|
|
|
|
Dear all
how to change the background color of dialog, i have done some code below, pls help me to check, however i couldn't change the background color after i picked the color. thanks.
void CMeiTengDlg::OnBnClickedChangebkcolor()
{
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
COLORREF color=dlg.GetColor();
}
|
|
|
|
|
|
thanks, malli
i would like to use this way what i mentioned in the previous post. how can i achieve it? thanks a lot.
|
|
|
|
|
Delete the old brush and update the brush color by creating the new one
m_brush.CreateSolidBrush(RGB(255, 255, 255));
with the selected color.
|
|
|
|
|
thanks malli
don't understand well, i wanna change different color for different person, when someone click change background color. so i need a changbackground(COLORREF color), don't how to write down it. thanks. could you help me. thanks.
i tried your that way, just can change once.
|
|
|
|
|
I hope following code snippet will help you. I've not included the details in depth. Just try it out.
class CMeiTengDlg: public CDialog
{
...
protected:
CBrush m_objMyBrush;
...
};
BOOL CMyDlg::OnInitDialog()
{
...
m_objMyBrush.CreateSolidBrush(RGB(255, 255, 255));
...
}
BOOL CMyDlg::DistroyWindow()
{
m_objMyBrush.DeleteObject();
}
HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
return m_objMyBrush;
}
void CMeiTengDlg::OnBnClickedChangebkcolor()
{
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
COLORREF color=dlg.GetColor();
changbackground(color);
}
void CMeiTengDlg::changbackground(COLORREF color)
{
m_objMyBrush.DeleteObject();
m_objMyBrush.CreateSolidBrush( color );
Invalidate(TRUE);
}
|
|
|
|
|
thanks Malli
i want to confirm i just wanna change my CMeiTengDlg background color, what mentioned above is CMyDlg, CAboutDlg, so i no need to add one class, right? so i followed your idea, but after compiled, one error is
c:\documents and settings\zhiyuan li\desktop\meiteng\meiteng\meitengdlg.cpp(163) : error C4716: 'CMeiTengDlg::DistroyWindow' : must return a value<br />
Build log was saved at "file://c:\Documents and Settings\ZhiYuan Li\Desktop\MeiTeng\MeiTeng\Debug\BuildLog.htm"<br />
MeiTeng - 1 error(s), 0 warning(s)
by the way,could i get your email, and keep in touch. thanks.
|
|
|
|
|
Sorry Zhiyuan16,
I forgot to replace the CMyDls with your dialog class name. And you should return value from DestroyWindow function. I had deleted rest of the code (and put ....) considering you'd put the required one. For details have a look at here[^]
|
|
|
|
|
thanks Malli
comiling had no problem, but still no color change of background after i chose different color.
where is problem, Malli? thanks
|
|
|
|
|
dear Malli
could you help me to check is it right below: thanks a lot
BOOL CMeiTengDlg::OnDestroyWindow()<br />
{<br />
m_objMyBrush.DeleteObject();<br />
return TRUE;<br />
}<br />
<br />
<br />
HBRUSH CMeiTengDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)<br />
{<br />
<br />
return m_objMyBrush;<br />
}<br />
<br />
void CMeiTengDlg::SetBackgroundColor(COLORREF color)<br />
{<br />
m_objMyBrush.DeleteObject(); <br />
m_objMyBrush.CreateSolidBrush( color ); <br />
<br />
Invalidate(TRUE);<br />
}<br />
<br />
void CMeiTengDlg::OnBnClickedChangebkcolor()<br />
{<br />
CColorDialog dlg;<br />
if (dlg.DoModal() == IDOK) <br />
color=dlg.GetColor(); <br />
SetBackgroundColor(color);<br />
}<br />
|
|
|
|
|
The above code worked for me (only 'color' variable I found missing). Do you have any overlapping control on your dialog ? And I think you should call
return CDialog::DestroyWindow();
in your dialog's DistroyWindow();
|
|
|
|
|
no other control..
Malli
could you check for me the following my dialog .h and .cpp files thanks.
CMeiTengDlg.h file
#pragma once
#include "afxwin.h"
class CMeiTengDlg : public CDialog
{
public:
CMeiTengDlg(CWnd* pParent = NULL);
void SetBackgroundColor(COLORREF color);
enum { IDD = IDD_MEITENG_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
HICON m_hIcon;
CBrush m_objMyBrush;
COLORREF color;
virtual BOOL OnInitDialog();
virtual BOOL OnDistroyWindow();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
DECLARE_MESSAGE_MAP()
public:
CComboBox m_pComboBox;
afx_msg void OnBnClickedChangebkcolor();
};
CMeiTengDlg.cpp file
#include "stdafx.h"
#include "MeiTeng.h"
#include "MeiTengDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
CMeiTengDlg::CMeiTengDlg(CWnd* pParent )
: CDialog(CMeiTengDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMeiTengDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_BITMAP, m_pComboBox);
}
BEGIN_MESSAGE_MAP(CMeiTengDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ChangeBKColor, &CMeiTengDlg::OnBnClickedChangebkcolor)
END_MESSAGE_MAP()
BOOL CMeiTengDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_objMyBrush.CreateSolidBrush(RGB(255, 255, 255));
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
return TRUE;
}
void CMeiTengDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CMeiTengDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CMeiTengDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
BOOL CMeiTengDlg::OnDistroyWindow()
{
m_objMyBrush.DeleteObject();
return CDialog::DestroyWindow();
}
HBRUSH CMeiTengDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
return m_objMyBrush;
}
void CMeiTengDlg::SetBackgroundColor(COLORREF color)
{
m_objMyBrush.DeleteObject();
m_objMyBrush.CreateSolidBrush( color );
Invalidate(TRUE);
}
void CMeiTengDlg::OnBnClickedChangebkcolor()
{
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
color=dlg.GetColor();
SetBackgroundColor(color);
}
|
|
|
|