# man pages section 3: Extended Library Functions, Volume 4

Updated: Thursday, June 13, 2019

### Synopsis

```cc [ flag ... ] file ...  -lsunmath -lm [ library ... ]
```
```#include <sunmath.h>
```
```int i_addran_(void);
```
```float r_addran_(void);
```
```double d_addran_(void);
```
```void i_addrans_(int *x, int *n, int *l, int *u);
```
```void  u_addrans_(unsigned  *x, int *n, unsigned *l, unsigned *u);
```
```void r_addrans_(float *x, int *n, float *l, float *u);
```
```void d_addrans_(double *x, int *n, double *l, double *u);
```
```void i_get_addrans_(int *x);
```
```void r_get_addrans_(float *x);
```
```void d_get_addrans_(double *x);
```
```void i_set_addrans_(int *x);
```
```void r_set_addrans_(float *x);
```
```void d_set_addrans_(double *x);
```
```void i_init_addrans_(void);
```
```void r_init_addrans_(void);
```
```void d_init_addrans_(void);
```

### Description

These functions generate uniformly distributed random numbers of types int, unsigned int, float, or double. Each function generates the next random number in sequence using a recurrence of the form

```
next = table[i] - table[(i - 24) % ADDRAN_SIZE];
table[i] = next;
i = (i + 1) % ADDRAN_SIZE;
```

Internally, these functions maintain three separate tables of ADDRAN_SIZE elements for each thread in a program. ADDRAN_SIZE is defined in <sunmath.h>.

i_addran_() returns a random 32-bit integer. Successive numbers are computed in 32-bit integer arithmetic (i.e., modulo 2**32) and thus lie in the range -2147483648, ..., 2147483647.

r_addran_() returns a random single precision floating point number between 0 and 1 - 2**-24. Successive numbers are kept in this range by adding 1 when necessary.

d_addran_() returns a random double precision floating point number between 0 and 1 - 2**-53. Successive numbers are kept in this range by adding 1 when necessary.

i_addrans_(n, x, l, u), u_addrans_(n, x, l, u), r_addrans_(n, x, l, u), and d_addrans_(n, x, l, u) each fill the array elements x, ..., x[*n-1] with random 32-bit signed integers, 32-bit unsigned integers, single precision floating point numbers and double precision floating point numbers, respectively. The numbers are scaled and offset so as to be uniformly distributed over the interval [*l, *u].

### Examples

To generate 1000 random double precision numbers in [0,1):

```
double x;
int i;

for (i = 0; i < 1000; i++)
```

The same numbers can be generated more efficiently using:

```
double x, lb, ub;
int n = 1000;

lb = D_ADDRAN_LB; /* defined in <sunmath.h> */
ub = D_ADDRAN_UB; /* defined in <sunmath.h> */
```

To generate 1000 random integers between -10 and 10:

```int x, n = 1000, lb = -10, ub = 10;
```

### Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
MT-Safe
Availability
system/library/math