Click here to Skip to main content
15,892,161 members
Articles / Programming Languages / C++

A Normal / Exponential Random Generator and Histogram Class

Rate me:
Please Sign up or sign in to vote.
4.73/5 (11 votes)
2 Dec 20024 min read 276.8K   8.1K   55  
A fast random generator with normal or exponential distribution + a histogram class
In this article, you will find a fast generator for Random Variable, namely normal and exponential distributions. It is based on George Marsaglia's and Wai Wan Tsang's work.
// HistogramDemoView.cpp : implementation of the CHistogramDemoView class
//

#include "stdafx.h"
#include "HistogramDemo.h"

#include "HistogramDemoDoc.h"
#include "HistogramDemoView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CHistogramDemoView

IMPLEMENT_DYNCREATE(CHistogramDemoView, CView)

BEGIN_MESSAGE_MAP(CHistogramDemoView, CView)
	//{{AFX_MSG_MAP(CHistogramDemoView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHistogramDemoView construction/destruction

CHistogramDemoView::CHistogramDemoView()
{
	// TODO: add construction code here

}

CHistogramDemoView::~CHistogramDemoView()
{
}

BOOL CHistogramDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CHistogramDemoView drawing

void CHistogramDemoView::OnDraw(CDC* pDC)
{
	CHistogramDemoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CHistogramDemoView diagnostics

#ifdef _DEBUG
void CHistogramDemoView::AssertValid() const
{
	CView::AssertValid();
}

void CHistogramDemoView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CHistogramDemoDoc* CHistogramDemoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHistogramDemoDoc)));
	return (CHistogramDemoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CHistogramDemoView message handlers

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

Comments and Discussions