欢迎来到天天文库
浏览记录
ID:40777080
大小:99.28 KB
页数:6页
时间:2019-08-07
《产生高斯随机数》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、一、产生0-1均匀分布数采用混合同余法,,,即为一个在0~1之间的随机数。通常情况下,选取,我们任意给定一个初始值,即可得到一个随机数,在程序中采用指针变量*s,使得每次产生的随机数都不一样,只要改变循环的次数,就可以得到任意多个0~1随机数。程序实现代码如下:doublex1(doublea,doubleb,int*s){doublet;*s=2045*(*s)+1;*s=*s-(*s/1048576)*1048576;t=(*s)/1048576.0;return(t);}二、产生标准高斯分布数标准的高斯分布均值=0,方差=1;根据中心极限定理有,根据此式可以由12
2、个0~1分布数产生一个高斯数。改变循环次数可以得到任意多个标准高斯分布数。程序实现代码如下:intmain(){doublemean,sigma;doublex[100];inti,j;ints;mean=0.0;sigma=1.0;s=19444;cout<<"产生个高斯数:"<3、<#include//#include#include#include#include#include#include4、>#includelongWINAPIWndProc(HWNDhWnd,UINTiMessage,UINTwParam,LONGlParam);BOOLInitWindowsClass(HINSTANCEhInstance);BOOLInitWindows(HINSTANCEhInstance,intnCmdShow);intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow){MSGMessage;if(!InitWindowsClass(5、hInstance))returnFALSE;if(!InitWindows(hInstance,nCmdShow))returnFALSE;while(GetMessage(&Message,0,0,0)){TranslateMessage(&Message);DispatchMessage(&Message);}returnMessage.wParam;}longWINAPIWndProc(HWNDhWnd,UINTiMessage,UINTwParam,LONGlParam){HDChDC;HBRUSHhBrush;HPENhPen;PAINTSTRUCTPtSt6、r;////////////////////////////doublex1(doublea,doubleb,int*s);doublemean=0,sigma=1.0;srand((unsigned)time(NULL));doublex[10000],b[10000]={0},temp;inti,j;ints1;intk;s1=19444;for(j=0;j<10000;j++){x[j]=0;for(i=0;i<12;i++){x[j]=x[j]+x1(mean,sigma,&s1);}x[j]=x[j]-6.0;}for(i=0;i<10000;i++){tem7、p=x[i];//printf("%lft",temp);for(j=0;j<10000;j++){if(-3+0.2*jtemp)b[j]=b[j]+1;}}/////////////////////////////////switch(iMessage){caseWM_PAINT:hDC=BeginPaint(hWnd,&PtStr);SetMapMode(hDC,MM_ANISOTROPIC);hPen=(HPEN)GetStockObject(BLACK_PEN);hBrush=(HBRU
3、<#include//#include#include#include#include#include#include4、>#includelongWINAPIWndProc(HWNDhWnd,UINTiMessage,UINTwParam,LONGlParam);BOOLInitWindowsClass(HINSTANCEhInstance);BOOLInitWindows(HINSTANCEhInstance,intnCmdShow);intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow){MSGMessage;if(!InitWindowsClass(5、hInstance))returnFALSE;if(!InitWindows(hInstance,nCmdShow))returnFALSE;while(GetMessage(&Message,0,0,0)){TranslateMessage(&Message);DispatchMessage(&Message);}returnMessage.wParam;}longWINAPIWndProc(HWNDhWnd,UINTiMessage,UINTwParam,LONGlParam){HDChDC;HBRUSHhBrush;HPENhPen;PAINTSTRUCTPtSt6、r;////////////////////////////doublex1(doublea,doubleb,int*s);doublemean=0,sigma=1.0;srand((unsigned)time(NULL));doublex[10000],b[10000]={0},temp;inti,j;ints1;intk;s1=19444;for(j=0;j<10000;j++){x[j]=0;for(i=0;i<12;i++){x[j]=x[j]+x1(mean,sigma,&s1);}x[j]=x[j]-6.0;}for(i=0;i<10000;i++){tem7、p=x[i];//printf("%lft",temp);for(j=0;j<10000;j++){if(-3+0.2*jtemp)b[j]=b[j]+1;}}/////////////////////////////////switch(iMessage){caseWM_PAINT:hDC=BeginPaint(hWnd,&PtStr);SetMapMode(hDC,MM_ANISOTROPIC);hPen=(HPEN)GetStockObject(BLACK_PEN);hBrush=(HBRU
4、>#includelongWINAPIWndProc(HWNDhWnd,UINTiMessage,UINTwParam,LONGlParam);BOOLInitWindowsClass(HINSTANCEhInstance);BOOLInitWindows(HINSTANCEhInstance,intnCmdShow);intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow){MSGMessage;if(!InitWindowsClass(
5、hInstance))returnFALSE;if(!InitWindows(hInstance,nCmdShow))returnFALSE;while(GetMessage(&Message,0,0,0)){TranslateMessage(&Message);DispatchMessage(&Message);}returnMessage.wParam;}longWINAPIWndProc(HWNDhWnd,UINTiMessage,UINTwParam,LONGlParam){HDChDC;HBRUSHhBrush;HPENhPen;PAINTSTRUCTPtSt
6、r;////////////////////////////doublex1(doublea,doubleb,int*s);doublemean=0,sigma=1.0;srand((unsigned)time(NULL));doublex[10000],b[10000]={0},temp;inti,j;ints1;intk;s1=19444;for(j=0;j<10000;j++){x[j]=0;for(i=0;i<12;i++){x[j]=x[j]+x1(mean,sigma,&s1);}x[j]=x[j]-6.0;}for(i=0;i<10000;i++){tem
7、p=x[i];//printf("%lft",temp);for(j=0;j<10000;j++){if(-3+0.2*jtemp)b[j]=b[j]+1;}}/////////////////////////////////switch(iMessage){caseWM_PAINT:hDC=BeginPaint(hWnd,&PtStr);SetMapMode(hDC,MM_ANISOTROPIC);hPen=(HPEN)GetStockObject(BLACK_PEN);hBrush=(HBRU
此文档下载收益归作者所有