Skip to content

Commit

Permalink
Some C++ updating.
Browse files Browse the repository at this point in the history
  • Loading branch information
emeryberger committed Aug 18, 2017
1 parent 1b73b90 commit 3acf53f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/include/rng/mwc.h
@@ -1,34 +1,37 @@
// -*- C++ -*-

#ifndef _MWC_H_
#define _MWC_H_
#ifndef MWC_H_
#define MWC_H_

#include <stdint.h>

/**
* @class MWC
* @brief A super-fast multiply-with-carry pseudo-random number generator.
* @author Emery Berger <http://www.cs.umass.edu/~emery>
* @note Copyright (C) 2005-2011 by Emery Berger, University of Massachusetts Amherst.
* @author Emery Berger <http://www.emeryberger.com>
* @note Copyright (C) 2005-2017 by Emery Berger, University of Massachusetts Amherst.
*/

class MWC {
public:

MWC (unsigned int seed1, unsigned int seed2)
MWC (uint32_t seed1, uint32_t seed2)
: z (seed1), w (seed2)
{}

inline unsigned int next (void) {
inline uint32_t next (void) {
// These magic numbers are derived from a note by George Marsaglia.
unsigned int znew = (z=36969*(z&65535)+(z>>16));
unsigned int wnew = (w=18000*(w&65535)+(w>>16));
unsigned int x = (znew << 16) + wnew;
// See below.
uint32_t znew = (z=36969*(z&65535)+(z>>16));
uint32_t wnew = (w=18000*(w&65535)+(w>>16));
uint32_t x = (znew << 16) + wnew;
return x;
}

private:

unsigned int z;
unsigned int w;
uint32_t z;
uint32_t w;

};

Expand Down

0 comments on commit 3acf53f

Please sign in to comment.