46 #if !defined(_POSIX_THREAD_SAFE_FUNCTIONS) 51 return rand_r(&(state->
seed));
53 std::lock_guard<std::mutex> lock(_RandMutex);
77 if (prob == 0)
return false;
78 else if (prob == 1.0)
return true;
79 else if (prob * RAND_MAX < 128.0) {
83 if (
Rand(state) < RAND_MAX / 128) {
91 return (
Rand(state) < ((RAND_MAX + static_cast<BaseFloat>(1.0)) * prob));
98 if (max_val == min_val)
return min_val;
102 if (RAND_MAX > (max_val-min_val)*8) {
105 ((
unsigned int)
Rand(state) % (
unsigned int)(max_val+1-min_val));
107 if ((
unsigned int)(RAND_MAX*RAND_MAX) >
108 (
unsigned int)((max_val+1-min_val)*8)) {
110 return min_val + ( (
unsigned int)( (
Rand(state)+RAND_MAX*
Rand(state)))
111 % (
unsigned int)(max_val+1-min_val));
113 KALDI_ERR <<
"rand_int failed because we do not support such large " 114 "random numbers. (Extend this function).";
119 (
static_cast<int32>(
Rand(state)) % static_cast<int32>(max_val+1-min_val));
129 float L = expf(-lambda), p = 1.0;
144 u1 = sqrtf(-2.0f * logf(u1));
145 u2 = 2.0f *
M_PI * u2;
153 float a_float, b_float;
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
bool WithProb(BaseFloat prob, struct RandomState *state)
int32 RoundUpToNearestPowerOfTwo(int32 n)
int32 RandPoisson(float lambda, struct RandomState *state)
static std::mutex _RandMutex
void RandGauss2(float *a, float *b, RandomState *state)
int Rand(struct RandomState *state)
#define KALDI_ASSERT(cond)
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
#define KALDI_COMPILE_TIME_ASSERT(b)