mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Fixed indent.
This commit is contained in:
194
include/bx/rng.h
194
include/bx/rng.h
@@ -1,97 +1,97 @@
|
||||
/*
|
||||
* Copyright 2010-2012 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __BX_RNG_H__
|
||||
#define __BX_RNG_H__
|
||||
|
||||
#include "bx.h"
|
||||
|
||||
namespace bx
|
||||
{
|
||||
// George Marsaglia's MWC
|
||||
class RngMwc
|
||||
{
|
||||
public:
|
||||
RngMwc(uint32_t _z = 12345, uint32_t _w = 65435)
|
||||
: m_z(_z)
|
||||
, m_w(_w)
|
||||
{
|
||||
}
|
||||
|
||||
void reset(uint32_t _z = 12345, uint32_t _w = 65435)
|
||||
{
|
||||
m_z = _z;
|
||||
m_w = _w;
|
||||
}
|
||||
|
||||
uint32_t gen()
|
||||
{
|
||||
m_z = 36969*(m_z&65535)+(m_z>>16);
|
||||
m_w = 18000*(m_w&65535)+(m_w>>16);
|
||||
return (m_z<<16)+m_w;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_z;
|
||||
uint32_t m_w;
|
||||
};
|
||||
|
||||
// George Marsaglia's FIB
|
||||
class RngFib
|
||||
{
|
||||
public:
|
||||
RngFib()
|
||||
: m_a(9983651)
|
||||
, m_b(95746118)
|
||||
{
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
m_a = 9983651;
|
||||
m_b = 95746118;
|
||||
}
|
||||
|
||||
uint32_t gen()
|
||||
{
|
||||
m_b = m_a+m_b;
|
||||
m_a = m_b-m_a;
|
||||
return m_a;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_a;
|
||||
uint32_t m_b;
|
||||
};
|
||||
|
||||
// George Marsaglia's SHR3
|
||||
class RngShr3
|
||||
{
|
||||
public:
|
||||
RngShr3(uint32_t _jsr = 34221)
|
||||
: m_jsr(_jsr)
|
||||
{
|
||||
}
|
||||
|
||||
void reset(uint32_t _jsr = 34221)
|
||||
{
|
||||
m_jsr = _jsr;
|
||||
}
|
||||
|
||||
uint32_t gen()
|
||||
{
|
||||
m_jsr ^= m_jsr<<17;
|
||||
m_jsr ^= m_jsr>>13;
|
||||
m_jsr ^= m_jsr<<5;
|
||||
return m_jsr;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_jsr;
|
||||
};
|
||||
|
||||
} // namespace bx
|
||||
|
||||
#endif // __BX_RNG_H__
|
||||
/*
|
||||
* Copyright 2010-2012 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __BX_RNG_H__
|
||||
#define __BX_RNG_H__
|
||||
|
||||
#include "bx.h"
|
||||
|
||||
namespace bx
|
||||
{
|
||||
// George Marsaglia's MWC
|
||||
class RngMwc
|
||||
{
|
||||
public:
|
||||
RngMwc(uint32_t _z = 12345, uint32_t _w = 65435)
|
||||
: m_z(_z)
|
||||
, m_w(_w)
|
||||
{
|
||||
}
|
||||
|
||||
void reset(uint32_t _z = 12345, uint32_t _w = 65435)
|
||||
{
|
||||
m_z = _z;
|
||||
m_w = _w;
|
||||
}
|
||||
|
||||
uint32_t gen()
|
||||
{
|
||||
m_z = 36969*(m_z&65535)+(m_z>>16);
|
||||
m_w = 18000*(m_w&65535)+(m_w>>16);
|
||||
return (m_z<<16)+m_w;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_z;
|
||||
uint32_t m_w;
|
||||
};
|
||||
|
||||
// George Marsaglia's FIB
|
||||
class RngFib
|
||||
{
|
||||
public:
|
||||
RngFib()
|
||||
: m_a(9983651)
|
||||
, m_b(95746118)
|
||||
{
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
m_a = 9983651;
|
||||
m_b = 95746118;
|
||||
}
|
||||
|
||||
uint32_t gen()
|
||||
{
|
||||
m_b = m_a+m_b;
|
||||
m_a = m_b-m_a;
|
||||
return m_a;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_a;
|
||||
uint32_t m_b;
|
||||
};
|
||||
|
||||
// George Marsaglia's SHR3
|
||||
class RngShr3
|
||||
{
|
||||
public:
|
||||
RngShr3(uint32_t _jsr = 34221)
|
||||
: m_jsr(_jsr)
|
||||
{
|
||||
}
|
||||
|
||||
void reset(uint32_t _jsr = 34221)
|
||||
{
|
||||
m_jsr = _jsr;
|
||||
}
|
||||
|
||||
uint32_t gen()
|
||||
{
|
||||
m_jsr ^= m_jsr<<17;
|
||||
m_jsr ^= m_jsr>>13;
|
||||
m_jsr ^= m_jsr<<5;
|
||||
return m_jsr;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_jsr;
|
||||
};
|
||||
|
||||
} // namespace bx
|
||||
|
||||
#endif // __BX_RNG_H__
|
||||
|
||||
Reference in New Issue
Block a user