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 219 by chuckv, Sun Dec 29 19:12:06 2002 UTC vs.
Revision 250 by chuckv, Mon Jan 27 22:12:57 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 < randomSPRNG::randomSPRNG(){
12 > /* randomStreamSPRNF creates a new SPRNG stream for random numbers
13 > */
14  
15 + int randomSPRNG::nStreamsInitialized = 0;
16  
17 + randomSPRNG::randomSPRNG(int 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
32 +
33 +  nSPRNGStreams = 1;
34 +  myStreamNumber = nStreamsInitialized;
35 +
36 + #endif
37 +
38 +  thisStream = init_sprng(GTYPE,myStreamNumber,nSPRNGStreams,
39 +                          newSeed,SPRNG_DEFAULT);
40   }
41 +
42 + randomSPRNG::~randomSPRNG(){
43 +
44 +  free_sprng(*thisStream);
45 +  nStreamsInitialized--;
46 +
47 + }
48 +
49 +
50 + double randomSPRNG::getRandom(){
51 +  return sprng(thisStream);
52 + }
53 +
54 +
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