ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/md_code/randomSPRNG.cpp
(Generate patch)

Comparing trunk/mdtools/md_code/randomSPRNG.cpp (file contents):
Revision 220 by chuckv, Mon Dec 30 16:20:42 2002 UTC vs.
Revision 223 by chuckv, Fri Jan 3 22:04:50 2003 UTC

# Line 3 | Line 3
3  
4   #include "randomSPRNG.hpp"
5   #include "simError.h"
6 + #include "sprng.h"
7  
8 + #ifdef IS_MPI
9 + #include "mpiSimulation.hpp"
10 + #endif
11  
12   /* randomStreamSPRNF creates a new SPRNG stream for random numbers
13   */
14  
15 < int ranStreamSPRNG::nSPRNGStreams;
15 > int randomSPRNG::nStreamsInitialized = 0;
16  
17 < randomStreamSPRNG::randomStreamSPRNG(){
17 > randomSPRNG::randomSPRNG(iseed){
18 >  int newSeed;
19 >  nStreamsInitialized++;
20 >  newSeed = abs(iseed) + nStreamsInitialized;  
21 >  if( newSeed < 0 ) newSeed = abs( newSeed );
22 >
23   #ifdef IS_MPI
24  
25 +  nSPRNGStreams = mpiSim->getNumberProcessors();
26 +
27 +  myStreamNumber = mpiSim->getMyNode();
28 +
29    
30  
31   #else
19  nSPRNGStreams++;
32  
33 <  myStreamNumber = nSPRNGStreams;
33 >  nSPRNGStreams = 1;
34 >  myStreamNumber = nStreamsInitialized;
35  
23  thisStream = init_sprng(GTYPE,streamnum,nstreams,SEED,SPRNG_DEFAULT);
24
25
36   #endif
37 +
38 +  thisStream = init_sprng(GTYPE,myStreamNumber,nSPRNGStreams,
39 +                          newSeed,SPRNG_DEFAULT);
40   }
41  
42 < randomStreamSPRNG::~randomStreamSPRNG(){
42 > randomSPRNG::~randomSPRNG(){
43  
44    free_sprng(int *thisStream);
45 <  nSPRNGStreams--;
45 >  nStreamsInitialized--;
46  
47 + }
48  
49 +
50 + double randomSPRNG::getRandom(){
51 +  return sprng(thisStream);
52   }
53  
54  
55 < double getRanStreamSPRNG(){
56 <  double ranNum;
57 <  nanNum = sprng(thisStream);
58 <  return ranNum;
55 > // Gaussian SPRNG class...
56 >
57 > double gaussianSPRNG::getGaussian(){
58 >  double ranNum1;
59 >  double ranNum2;
60 >  double gaussianNumber;
61 >
62 >  ranNum1 = getRandom();
63 >  ranNum2 = getRandom();
64 >
65 >  gaussianNumber = sqrt(-2.0 * log(ranNum1)) * cos(2 * M_PI * ranNum2);
66 >
67 >  return gaussianNumber;
68   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines