Rate This Document
Findability
Accuracy
Completeness
Readability

Poisson Distribution Function

Generate a random number vector that conforms to Poisson distribution.

Interface Definition

int viRngPoisson (const int method, VSLStreamStatePtr stream, const SizeType n, int *r, const double lambda);

Probability Density Function

Parameters

Parameter

Type

Description

Input/Output

method

int

Random number generation method.

  • VSL_RNG_METHOD_POISSON_FAST: fast method.
  • VSL_RNG_METHOD_POISSON_ACCURATE: accurate method.

Input

stream

VSLStreamStatePtr type

Random number stream.

Input

n

SizeType

Length of the output vector.

Input

r

Integer pointer

Pointer to the result.

Output

lambda

double

Lambda parameter of the Poisson distribution.

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;
    int *r = (int *)malloc(sizeof(int) * n);
    if (r == NULL) {
        fprintf(stderr, "Failure in malloc\n");
        return 0;
    }

    if (viRngPoisson(VSL_RNG_METHOD_POISSON_ACCURATE, stream, n, r, 2.0)) {
        fprintf(stderr, "Failure in viRngPoisson\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;
}