RandGauss
Generates a random sequence that complies with normal distribution and has a given mean value and standard deviation.
The function interface declaration is as follows:
- Initialization:
HmppResult HMPPS_RandGaussInit_8u(HmppsRandGaussPolicy_8u **policy, uint8_t mean, uint8_t stdDev, uint32_t seed);
HmppResult HMPPS_RandGaussInit_16s(HmppsRandGaussPolicy_16s **policy, int16_t mean, int16_t stdDev, uint32_t seed);
HmppResult HMPPS_RandGaussInit_32f(HmppsRandGaussPolicy_32f **policy, float mean, float stdDev, uint32_t seed);
HmppResult HMPPS_RandGaussInit_64f(HmppsRandGaussPolicy_64f **policy, double mean, double stdDev, uint32_t seed);
- Main functions:
HmppResult HMPPS_RandGauss_8u(uint8_t *dst, int32_t len, HmppsRandGaussPolicy_8u *policy);
HmppResult HMPPS_RandGauss_16s(int16_t *dst, int32_t len, HmppsRandGaussPolicy_16s *policy);
HmppResult HMPPS_RandGauss_32f(float *dst, int32_t len, HmppsRandGaussPolicy_32f *policy);
HmppResult HMPPS_RandGauss_64f(double *dst, int32_t len, HmppsRandGaussPolicy_64f *policy);
- Memory release:
HmppResult HMPPS_RandGaussRelease_8u(HmppsRandGaussPolicy_8u *policy);
HmppResult HMPPS_RandGaussRelease_16s(HmppsRandGaussPolicy_16s *policy);
HmppResult HMPPS_RandGaussRelease_32f(HmppsRandGaussPolicy_32f *policy);
HmppResult HMPPS_RandGaussRelease_64f(HmppsRandGaussPolicy_64f *policy);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
len |
Vector length |
(0, INT_MAX] |
Input |
mean |
Mean value |
Depending on the type |
Input |
stdDev |
Standard deviation |
Depending on the type |
Input |
seed |
Random number seed |
Depending on the type |
Input |
policy |
Parameter structure for generating a random sequence |
The value cannot be NULL. |
Input/Output |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
The value of dst is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
HMPP_STS_MALLOC_FAILED |
Failed to allocate the required extra memory. |
Example
#define BUFFER_SIZE_T 10
int main()
{
float dst[BUFFER_SIZE_T];
int32_t i;
float mean = 1;
float stdDev = 1;
float seed = 0;
HmppsRandGaussPolicy_32f *policy = NULL;
HmppResult result;
result = HMPPS_RandGaussInit_32f(&policy, mean, stdDev, seed);
if (result != HMPP_STS_NO_ERR)
{
return;
}
result = HMPPS_RandGauss_32f(dst, BUFFER_SIZE_T, policy);
printf("result = %d \ndst =", result);
for (i = 0; i < BUFFER_SIZE_T; i++) {
printf(" %f ", dst[i]);
}
HMPPS_RandGaussRelease_32f(policy);
return 0;
}
Output:
result = 0 dst = 0.839658 0.516040 0.405604 0.981364 2.000319 -0.703950 0.667630 1.412678 1.724619 1.078169