Click here to Skip to main content
15,881,248 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: (*&#@*!^ Templates Pin
Gary R. Wheeler11-Apr-10 1:31
Gary R. Wheeler11-Apr-10 1:31 
GeneralRe: (*&#@*!^ Templates Pin
Tim Craig11-Apr-10 9:36
Tim Craig11-Apr-10 9:36 
QuestionProblem in AT+CSCA command in AT commands. Pin
Le@rner9-Apr-10 19:29
Le@rner9-Apr-10 19:29 
Questionhow to implement three indepedent random number generators in the same subroutine/function Pin
mrby1239-Apr-10 17:34
mrby1239-Apr-10 17:34 
AnswerRe: how to implement three indepedent random number generators in the same subroutine/function Pin
Adam Roderick J9-Apr-10 18:09
Adam Roderick J9-Apr-10 18:09 
GeneralRe: how to implement three indepedent random number generators in the same subroutine/function Pin
mrby1239-Apr-10 18:25
mrby1239-Apr-10 18:25 
GeneralRe: how to implement three indepedent random number generators in the same subroutine/function Pin
Adam Roderick J9-Apr-10 19:23
Adam Roderick J9-Apr-10 19:23 
GeneralRe: how to implement three indepedent random number generators in the same subroutine/function [modified] Pin
mrby1239-Apr-10 19:40
mrby1239-Apr-10 19:40 
Thanks.

I am using a different random number generator which generates a normal distribution of a random number generator - N(0,1). This function is from a book called: Numerical Recipes.

When I call it, I call gasdev(int &idum); For example: t=time[i]+sd_error*gasdev(int &idum);
In one subroutine, I need to call gasdev(int &idum) three times, but I want each time it is independent.

int idum1=-1;
int idum2=-1;
int idum3=-1;
//
date=time[i]+t_sd_error*gasdev(idum1);
money=t_sd_error*gasdev(idum2);
force=force_sd_error*gasdev(idum3);

date, money, and force are totally independent variables. Do you think I am OK to make the three calls independent with above idum1, idum2, and idum3 ?


Here is it:

//
double C_procDlg::ran1(int &idum)
{
const int IA=16807,IM=2147483647,IQ=127773,IR=2836,NTAB=32;
const int NDIV=(1+(IM-1)/NTAB);
const double EPS=3.0e-16,AM=1.0/IM,RNMX=(1.0-EPS);
static int iy=0;
static int iv[100];
int j,k;
double temp;

if (idum<=0||!iy) { //initialize
if(-idum<1) idum=1;
else idum=-idum;
for(j=NTAB+7;j>=0;j--){
k=idum/IQ;
idum=IA*(idum-k*IQ)-IR*k;
if(idum<0) idum+=IM;
if(j<NTAB) iv[j]=idum;
//
}
iy=iv[0];
}
k=idum/IQ;
idum=IA*(idum-k*IQ)-IR*k;
if (idum<0) idum+=IM;
j=iy/NDIV;
iy=iv[j];
iv[j]=idum;
if((temp=AM*iy)>RNMX) return RNMX;
else return temp;
}
//
double CBlast_vib_procDlg::gasdev(int &idum)
{
static int iset=0;
static double gset;
double fac,rsq,v1,v2;
//
if(idum<0) iset=0;
if (iset==0){
do{
v1=2.0*ran1(idum)-1.0;
v2=2.0*ran1(idum)-1.0;
//
rsq=v1*v1+v2*v2;
}
while(rsq>=1.0||rsq==0.0);
fac=sqrt(-2.0*log(rsq)/rsq);
gset=v1*fac;
iset=1;
return v2*fac;
}
else{iset=0;
return gset;
}}
modified on Saturday, April 10, 2010 1:58 AM

GeneralRe: how to implement three indepedent random number generators in the same subroutine/function Pin
mrby12310-Apr-10 19:34
mrby12310-Apr-10 19:34 
GeneralRe: how to implement three indepedent random number generators in the same subroutine/function Pin
Adam Roderick J10-Apr-10 20:52
Adam Roderick J10-Apr-10 20:52 
GeneralRe: how to implement three indepedent random number generators in the same subroutine/function Pin
mrby12314-Apr-10 7:21
mrby12314-Apr-10 7:21 
GeneralRe: how to implement three indepedent random number generators in the same subroutine/function Pin
mrby12314-Apr-10 7:20
mrby12314-Apr-10 7:20 
Questionpost mouse move, wheel, RClick messages, (captured by CView) to the started thread Pin
m_code9-Apr-10 11:46
m_code9-Apr-10 11:46 
AnswerRe: post mouse move, wheel, RClick messages, (captured by CView) to the started thread Pin
Adam Roderick J9-Apr-10 18:11
Adam Roderick J9-Apr-10 18:11 
GeneralRe: post mouse move, wheel, RClick messages, (captured by CView) to the started thread Pin
m_code9-Apr-10 18:43
m_code9-Apr-10 18:43 
GeneralRe: post mouse move, wheel, RClick messages, (captured by CView) to the started thread Pin
Adam Roderick J9-Apr-10 19:12
Adam Roderick J9-Apr-10 19:12 
QuestionC++ class hierarchy design problem Pin
kylur9-Apr-10 9:00
kylur9-Apr-10 9:00 
AnswerRe: C++ class hierarchy design problem Pin
Jonathan Davies9-Apr-10 10:28
Jonathan Davies9-Apr-10 10:28 
GeneralRe: C++ class hierarchy design problem Pin
kylur12-Apr-10 9:47
kylur12-Apr-10 9:47 
AnswerRe: C++ class hierarchy design problem Pin
Bernódus Kristinsson9-Apr-10 11:04
Bernódus Kristinsson9-Apr-10 11:04 
GeneralRe: C++ class hierarchy design problem Pin
kylur12-Apr-10 10:25
kylur12-Apr-10 10:25 
AnswerRe: C++ class hierarchy design problem Pin
cmk9-Apr-10 14:52
cmk9-Apr-10 14:52 
GeneralRe: C++ class hierarchy design problem Pin
kylur12-Apr-10 10:09
kylur12-Apr-10 10:09 
GeneralRe: C++ class hierarchy design problem Pin
cmk12-Apr-10 12:45
cmk12-Apr-10 12:45 
AnswerRe: C++ class hierarchy design problem Pin
code_slashxx9-Apr-10 17:38
code_slashxx9-Apr-10 17:38 

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.