Mersenne twister

Hi there, I'm currently writing a program that accepts/rejects moves based on some other data (Monte Carlo simulation). My problem is with the Mersenne twister I am using to generate random numbers in the program. I can't pretend that my C++ knowledge is anywhere near that of the code written for Mersenne, so I'm only really just using it.

So I have two compiler files where I want to use the random number generator. The main file is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Random seed
		srand ( (unsigned int)time(0) );
		seedmain=time(NULL);
        
		// Starts the seqeunce of random numbers
		CRandomMersenne RanGen(seedmain);
		CRandomMersenne *pRanGen;
		pRanGen=&RanGen;
		double random;

    for (int i = 0; i < n_atoms; i++)
    {
		
		coords[i] = new double[3];
 		random=RanGen.Random();       
		coords[i][0] = random*box_size[0];
		random=RanGen.Random();
                coords[i][1] = random*box_size[1];
		random=RanGen.Random();
                coords[i][2] = random*box_size[2];

	}


Which works fine by itself. The problem is that I have now written another file that contains functions which are then called inside this main file. The section in this other file that is relevant is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
		// Acceptance Criteria 
			
		CRandomMersenne RanGen(seedmain);
		CRandomMersenne *pRanGen;
		pRanGen=&RanGen;
		double random2;

		random2=RanGen.Random();

		bool accept = false;

		if (random2 > acceptance_insert)
		{
			accept = true;
			naccept = naccept + 1;
			n_atoms = n_atoms+1;


Which returns the error "error C2082: redefinition of formal parameter 'pRanGen'". I've tried changing the above code a few times but just get errors like RanGen is undefined. Any help would be much appreciated.

Cheers.
It doesn't look like you use pRanGen for anything. Why not simply remove it?

Also, you could clean up that for a little bit:
1
2
3
4
5
for (int i = 0; i < n_atoms; i++){
    coords[i] = new double[3];
    for (int j = 0; j < 3; j++)
        coords[i][j] = RanGen.Random()*box_size[j];
}
Last edited on
Thanks Helios, I guess I didn't need pRanGen. Makes my life a bit easier.
Topic archived. No new replies allowed.