rewired some functions in qmc.h for better convenience
parent
ea3d61da15
commit
567b368fa6
|
@ -155,7 +155,6 @@ inline uint64_t sampleTEA(uint32_t v0, uint32_t v1, int rounds = 4) {
|
||||||
return ((uint64_t) v1 << 32) + v0;
|
return ((uint64_t) v1 << 32) + v0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DOUBLE_PRECISION)
|
|
||||||
/**
|
/**
|
||||||
* \brief Generate fast and reasonably good pseudorandom numbers using the
|
* \brief Generate fast and reasonably good pseudorandom numbers using the
|
||||||
* Tiny Encryption Algorithm (TEA) by David Wheeler and Roger Needham.
|
* Tiny Encryption Algorithm (TEA) by David Wheeler and Roger Needham.
|
||||||
|
@ -173,7 +172,35 @@ inline uint64_t sampleTEA(uint32_t v0, uint32_t v1, int rounds = 4) {
|
||||||
* \return
|
* \return
|
||||||
* A uniformly distributed floating point number on the interval <tt>[0, 1)</tt>
|
* A uniformly distributed floating point number on the interval <tt>[0, 1)</tt>
|
||||||
*/
|
*/
|
||||||
inline Float sampleTEAFloat(uint32_t v0, uint32_t v1, int rounds = 4) {
|
inline float sampleTEASingle(uint32_t v0, uint32_t v1, int rounds = 4) {
|
||||||
|
/* Trick from MTGP: generate an uniformly distributed
|
||||||
|
single precision number in [1,2) and subtract 1. */
|
||||||
|
union {
|
||||||
|
uint32_t u;
|
||||||
|
float f;
|
||||||
|
} x;
|
||||||
|
x.u = ((sampleTEA(v0, v1, rounds) & 0xFFFFFFFF) >> 9) | 0x3f800000UL;
|
||||||
|
return x.f - 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Generate fast and reasonably good pseudorandom numbers using the
|
||||||
|
* Tiny Encryption Algorithm (TEA) by David Wheeler and Roger Needham.
|
||||||
|
*
|
||||||
|
* This function uses \ref sampleTEA to return single precision floating point
|
||||||
|
* numbers on the interval <tt>[0, 1)</tt>
|
||||||
|
*
|
||||||
|
* \param v0
|
||||||
|
* First input value to be encrypted (could be the sample index)
|
||||||
|
* \param v1
|
||||||
|
* Second input value to be encrypted (e.g. the requested random number dimension)
|
||||||
|
* \param rounds
|
||||||
|
* How many rounds should be executed? The default for random number
|
||||||
|
* generation is 4.
|
||||||
|
* \return
|
||||||
|
* A uniformly distributed floating point number on the interval <tt>[0, 1)</tt>
|
||||||
|
*/
|
||||||
|
inline double sampleTEADouble(uint32_t v0, uint32_t v1, int rounds = 4) {
|
||||||
/* Trick from MTGP: generate an uniformly distributed
|
/* Trick from MTGP: generate an uniformly distributed
|
||||||
single precision number in [1,2) and subtract 1. */
|
single precision number in [1,2) and subtract 1. */
|
||||||
union {
|
union {
|
||||||
|
@ -184,33 +211,15 @@ inline Float sampleTEAFloat(uint32_t v0, uint32_t v1, int rounds = 4) {
|
||||||
return x.f - 1.0;
|
return x.f - 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#if defined(SINGLE_PRECISION)
|
||||||
/**
|
/// Alias to \ref sampleTEASingle or \ref sampleTEADouble based on compilation flags
|
||||||
* \brief Generate fast and reasonably good pseudorandom numbers using the
|
|
||||||
* Tiny Encryption Algorithm (TEA) by David Wheeler and Roger Needham.
|
|
||||||
*
|
|
||||||
* This function uses \ref sampleTEA to return single precision floating point
|
|
||||||
* numbers on the interval <tt>[0, 1)</tt>
|
|
||||||
*
|
|
||||||
* \param v0
|
|
||||||
* First input value to be encrypted (could be the sample index)
|
|
||||||
* \param v1
|
|
||||||
* Second input value to be encrypted (e.g. the requested random number dimension)
|
|
||||||
* \param rounds
|
|
||||||
* How many rounds should be executed? The default for random number
|
|
||||||
* generation is 4.
|
|
||||||
* \return
|
|
||||||
* A uniformly distributed floating point number on the interval <tt>[0, 1)</tt>
|
|
||||||
*/
|
|
||||||
inline Float sampleTEAFloat(uint32_t v0, uint32_t v1, int rounds = 4) {
|
inline Float sampleTEAFloat(uint32_t v0, uint32_t v1, int rounds = 4) {
|
||||||
/* Trick from MTGP: generate an uniformly distributed
|
return sampleTEASingle(v0, v1, rounds);
|
||||||
single precision number in [1,2) and subtract 1. */
|
}
|
||||||
union {
|
#else
|
||||||
uint32_t u;
|
/// Alias to \ref sampleTEASingle or \ref sampleTEADouble based on compilation flags
|
||||||
float f;
|
inline Float sampleTEAFloat(uint32_t v0, uint32_t v1, int rounds = 4) {
|
||||||
} x;
|
return sampleTEADouble(v0, v1, rounds);
|
||||||
x.u = ((sampleTEA(v0, v1, rounds) & 0xFFFFFFFF) >> 9) | 0x3f800000UL;
|
|
||||||
return x.f - 1.0f;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue