Rate This Document
Findability
Accuracy
Completeness
Readability

Log-normal Distribution Function

Generate a random number vector that conforms to log-normal distribution.

Interface Definition

int vsRngLognormal (const int method, VSLStreamStatePtr stream, const SizeType n, float *r, const float a, const float sigma, const float b, const float beta);

int vdRngLognormal (const int method, VSLStreamStatePtr stream, const SizeType n, double *r, const double a, const double sigma, const double b, const double beta);

Probability Density Function

Parameters

Parameter

Type

Description

Input/Output

method

int

Random number generation mode.

  • VSL_RNG_METHOD_LOGNORMAL_ICDF: inverse cumulative distribution function method
  • VSL_RNG_METHOD_LOGNORMAL_ICDF_ACCURATE: accurate inverse cumulative distribution function method

Input

stream

VSLStreamStatePtr type

Random number stream.

Input

n

SizeType

Length of the output vector.

Input

r

  • For vsRngLognormal, it is of single-precision floating-point type.
  • For vdRngLognormal, it is of double-precision floating-point type.

Pointer to the result.

Output

a

  • For vsRngLognormal, it is of single-precision floating-point type.
  • For vdRngLognormal, it is of double-precision floating-point type.

Parameter a, used to generate the inverse cumulative distribution function (ICDF) of Gaussian distribution.

Input

sigma

  • For vsRngLognormal, it is of single-precision floating-point type.
  • For vdRngLognormal, it is of double-precision floating-point type.

Parameter sigma, used to generate the inverse cumulative distribution function (ICDF) of Gaussian distribution.

Input

b

  • For vsRngLognormal, it is of single-precision floating-point type.
  • For vdRngLognormal, it is of double-precision floating-point type.

Addend of the operation result.

Input

beta

  • For vsRngLognormal, it is of single-precision floating-point type.
  • For vdRngLognormal, it is of double-precision floating-point type.

Multiplier of the operation result.

Input

Dependencies

#include "krng.h"

Examples

#include <stdio.h>
#include <stdlib.h>
#include "krng.h"
int main()
{
   /* initialize stream with given BRNG type and seed */
    VSLStreamStatePtr stream;
    unsigned seed = 42;
    int errcode = vslNewStream(&stream, VSL_BRNG_MCG59, seed);
    if (errcode != VSL_STATUS_OK) {
        fprintf(stderr, "Failure in newstream\n");
        return 0;
    }

    SizeType n = 10;
    float *r = (float *)malloc(sizeof(float) * n);
    if (r == NULL) {
        fprintf(stderr, "Failure in malloc\n");
        return 0;
    }

    if (vsRngLognormal(VSL_RNG_METHOD_LOGNORMAL_ICDF, stream, n, r, 5.0, 1.0, 6.0, 5.0)) {
        fprintf(stderr, "Failure in vsRngLognormal\n");
        goto out;
    }

    /* deinitialize the stream */
    errcode = vslDeleteStream(&stream);
    if (errcode != VSL_STATUS_OK) {
        fprintf(stderr, "Failure in deleting stream\n");
        goto out;
    }

out:
    free(r);
    return 0;
}