rewired some functions in qmc.h for better convenience
parent
ea3d61da15
commit
567b368fa6
|
@ -155,11 +155,10 @@ inline uint64_t sampleTEA(uint32_t v0, uint32_t v1, int rounds = 4) {
|
|||
return ((uint64_t) v1 << 32) + v0;
|
||||
}
|
||||
|
||||
#if defined(DOUBLE_PRECISION)
|
||||
/**
|
||||
* \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>
|
||||
*
|
||||
|
@ -173,7 +172,35 @@ inline uint64_t sampleTEA(uint32_t v0, uint32_t v1, int rounds = 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 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
|
||||
single precision number in [1,2) and subtract 1. */
|
||||
union {
|
||||
|
@ -184,33 +211,15 @@ inline Float sampleTEAFloat(uint32_t v0, uint32_t v1, int rounds = 4) {
|
|||
return x.f - 1.0;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* \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>
|
||||
*/
|
||||
#if defined(SINGLE_PRECISION)
|
||||
/// Alias to \ref sampleTEASingle or \ref sampleTEADouble based on compilation flags
|
||||
inline Float sampleTEAFloat(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;
|
||||
return sampleTEASingle(v0, v1, rounds);
|
||||
}
|
||||
#else
|
||||
/// Alias to \ref sampleTEASingle or \ref sampleTEADouble based on compilation flags
|
||||
inline Float sampleTEAFloat(uint32_t v0, uint32_t v1, int rounds = 4) {
|
||||
return sampleTEADouble(v0, v1, rounds);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue