14.2. Usage - 5.2 English - 57404

AOCL User Guide (57404)

Document ID
57404
Release Date
2025-12-29
Version
5.2 English

AOCL-RNG release package contains examples directory, which includes reference applications to demonstrate using APIs provided by library. CMake script is also provided to build and execute the programs. Provided CMake script works on both Linux as well as Windows. Refer examples/README.md file for more information.

Simple reference application is provided below to demonstrate about using AOCL-RNG.

  1. Include rng.h header file in your program.

  2. Link the appropriate version of libraries in your program.

  3. AOCL-RNG depends on AOCL-LibM and Single-threaded AOCL-BLAS libraries so link them all to your program.

  4. AOCL-RNG also depends on AOCL-SecureRNG library -lamdsecrng so same should be linked as well.

Listing 14.1 get_random.c#
 1#include <stdio.h>
 2#include <stdlib.h>
 3#include <rng.h>
 4
 5#define N          10
 6#define NAG_GENID  1
 7#define NAG_SUBID  0
 8#define SEED       123456
 9
10/*
11 * Base Generator : NAG Basic Generator
12 * Distribution   : Uniform Distribution
13 * RN Precision   : Double Precision
14 */
15
16int main()
17{
18  rng_int_t genid, subid, lseed, lstate, info;
19  rng_int_t seed[1] = {SEED};
20  rng_int_t *state  = NULL;
21  double a=0.0, b=1.0;
22  double rnum[N];
23
24  genid  = NAG_GENID;
25  subid  = NAG_SUBID;
26  lseed  = 1;
27  lstate = -1;
28
29  drandinitialize(genid, subid, seed, &lseed, state, &lstate, &info);
30  if (info < 0) {
31    printf("Error Code: %d \n", info);
32    exit(0);
33  }
34
35  state = (rng_int_t *) malloc(lstate * sizeof(rng_int_t));
36  /* skipping mem error check */
37
38  drandinitialize(genid, subid, seed, &lseed, state, &lstate, &info);
39  dranduniform(N, a, b, state, rnum, &info);
40  /* skipping error check */
41
42  for (int i=0; i<N; i++) {
43    printf("%10.4f \n", rnum[i]);
44  }
45
46  free(state);
47  return 0;
48}