Geometric Distribution Function
Generate a random number vector that conforms to geometric distribution.
Interface Definition
int viRngGeometric (const int method, VSLStreamStatePtr stream, const SizeType n, int *r, const double p);
Probability Density Function

Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
method |
int |
Random number generation 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 |
p |
double |
Probability of success in the geometric 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 (viRngGeometric(VSL_RNG_METHOD_GEOMETRIC_ICDF, stream, n, r, 0.5)) {
fprintf(stderr, "Failure in viRngGeometric\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;
}
Parent topic: High-performance Functions