21 #define GRT_DLL_EXPORTS 26 #if GRT_USE_CXX11_RANDOM_ALGO 27 Random::Random( ) : uniformRealDistribution(0.0,1.0), normalDistribution(0.0,1.0){}
29 Random::Random(
unsigned long long seed):v(4101842887655102017LL), w(1), storedval(0.0){
41 #if GRT_USE_CXX11_RANDOM_ALGO 42 generator.seed( seed_ );
44 unsigned long long seed = seed_;
49 v = 4101842887655102017LL;
52 u = seed ^ v; int64();
60 #if GRT_USE_CXX11_RANDOM_ALGO 61 std::uniform_int_distribution< int > uniformIntDistribution(minRange, maxRange-1);
62 return uniformIntDistribution( generator );
70 if( values.size() != weights.size() )
return 0;
72 unsigned int N = (
unsigned int)values.size();
74 for(
unsigned int i=0; i<N; i++){
75 weightedValues[i].index = values[i];
76 weightedValues[i].value = weights[i];
84 unsigned int N = (
unsigned int)weightedValues.size();
86 if( N == 0 )
return 0;
87 if( N == 1 )
return weightedValues[0].index;
90 sort(weightedValues.begin(),weightedValues.end(),IndexedDouble::sortIndexedDoubleByValueAscending);
94 x[0] = weightedValues[0].value;
95 for(
unsigned int i=1; i<N; i++){
96 x[i] = x[i-1] + weightedValues[i].value;
103 for(
unsigned int i=0; i<N; i++){
104 if( randValue <= x[i] ){
105 return weightedValues[ i ].index;
113 unsigned int N = (
unsigned int)weightedValues.size();
115 if( weightedValues.size() != x.size() )
return 0;
121 for(
unsigned int i=0; i<N; i++){
122 if( randValue <= x[i] ){
123 return weightedValues[ i ].index;
134 #if GRT_USE_CXX11_RANDOM_ALGO 135 Float r = uniformRealDistribution( generator );
139 return (r*(maxRange-minRange))+minRange;
147 #if GRT_USE_CXX11_RANDOM_ALGO 148 return mu + (normalDistribution( generator )*sigma);
152 if (storedval == 0.){
157 }
while (rsq >= 1.0 || rsq == 0.0);
158 fac=sqrt(-2.0*log(rsq)/rsq);
160 return mu + sigma*v2*fac;
164 return mu + sigma*fac;
171 for(UINT i=0; i<numDimensions; i++){
179 for(UINT i=0; i<numDimensions; i++){
187 const unsigned int rangeSize = endRange - startRange;
189 grt_assert( rangeSize > 0 );
190 grt_assert( endRange > startRange );
191 grt_assert( subsetSize <= rangeSize );
197 for(i=startRange; i<endRange; i++){
200 std::random_shuffle(indexs.begin(), indexs.end());
203 for(i=0; i<subsetSize; i++){
204 subset[i] = indexs[i];
VectorFloat getRandomVectorGauss(UINT numDimensions, Float mu=0.0, Float sigma=1.0)
Float getGauss(const Float &mu=0.0, const Float &sigma=1.0)
Float getRandomNumberGauss(Float mu=0.0, Float sigma=1.0)
Random(unsigned long long seed=0)
Vector< unsigned int > getRandomSubset(const unsigned int startRange, const unsigned int endRange, const unsigned int subsetSize)
int getRandomNumberWeighted(const Vector< int > &values, const VectorFloat &weights)
bool setSeed(const unsigned long long seed=0)
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)
Float getUniform(const Float &minRange=0.0, const Float &maxRange=1.0)
static unsigned long getSystemTime()