30 #ifndef GRT_RANDOM_HEADER
31 #define GRT_RANDOM_HEADER
35 #include "../Util/GRTVersionInfo.h"
48 Random(
unsigned long long seed = 0):v(4101842887655102017LL), w(1), storedval(0.0){
68 void setSeed(
unsigned long long seed = 0){
73 v = 4101842887655102017LL;
76 u = seed ^ v; int64();
107 if( values.size() != weights.size() )
return 0;
109 unsigned int N = (
unsigned int)values.size();
111 for(
unsigned int i=0; i<N; i++){
112 weightedValues[i].index = values[i];
113 weightedValues[i].value = weights[i];
131 unsigned int N = (
unsigned int)weightedValues.size();
133 if( N == 0 )
return 0;
134 if( N == 1 )
return weightedValues[0].index;
137 sort(weightedValues.begin(),weightedValues.end(),IndexedDouble::sortIndexedDoubleByValueAscending);
141 x[0] = weightedValues[0].value;
142 for(
unsigned int i=1; i<N; i++){
143 x[i] = x[i-1] + weightedValues[i].value;
150 for(
unsigned int i=0; i<N; i++){
151 if( randValue <= x[i] ){
152 return weightedValues[ i ].index;
175 unsigned int N = (
unsigned int)weightedValues.size();
177 if( weightedValues.size() != x.size() )
return 0;
183 for(
unsigned int i=0; i<N; i++){
184 if( randValue <= x[i] ){
185 return weightedValues[ i ].index;
199 return (doub()*(maxRange-minRange))+minRange;
212 if (storedval == 0.){
217 }
while (rsq >= 1.0 || rsq == 0.0);
218 fac=sqrt(-2.0*log(rsq)/rsq);
220 return mu + sigma*v2*fac;
224 return mu + sigma*fac;
238 for(UINT i=0; i<numDimensions; i++){
254 for(UINT i=0; i<numDimensions; i++){
271 const unsigned int rangeSize = endRange - startRange;
273 grt_assert( rangeSize > 0 );
274 grt_assert( endRange > startRange );
275 grt_assert( subsetSize <= rangeSize );
281 for(i=startRange; i<endRange; i++){
284 std::random_shuffle(indexs.begin(), indexs.end());
287 for(i=0; i<subsetSize; i++){
288 subset[i] = indexs[i];
295 inline unsigned long long int64() {
296 u = u * 2862933555777941757LL + 7046029254386353087LL;
297 v ^= v >> 17; v ^= v << 31; v ^= v >> 8;
298 w = 4294957665U*(w & 0xffffffff) + (w >> 32);
299 unsigned long long x = u ^ (u << 21); x ^= x >> 35; x ^= x << 4;
302 inline Float doub() {
return 5.42101086242752217E-20 * int64(); }
303 inline unsigned int int32() {
return (
unsigned int)int64(); }
305 unsigned long long u;
306 unsigned long long v;
307 unsigned long long w;
313 #endif //GRT_RANDOM_HEADER
VectorFloat getRandomVectorGauss(UINT numDimensions, Float mu=0.0, Float sigma=1.0)
Float getRandomNumberGauss(Float mu=0.0, Float sigma=1.0)
Vector< unsigned int > getRandomSubset(const unsigned int startRange, const unsigned int endRange, const unsigned int subsetSize)
int getRandomNumberWeighted(Vector< IndexedDouble > &weightedValues, VectorFloat &x)
int getRandomNumberWeighted(Vector< IndexedDouble > weightedValues)
int getRandomNumberWeighted(const Vector< int > &values, const VectorFloat &weights)
Float getRandomNumberUniform(Float minRange=0.0, Float maxRange=1.0)
int getRandomNumberInt(int minRange, int maxRange)
VectorFloat getRandomVectorUniform(UINT numDimensions, Float minRange=0.0, Float maxRange=1.0)
static unsigned long getSystemTime()
void setSeed(unsigned long long seed=0)
Random(unsigned long long seed=0)