1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#ifndef _NXT_RANDOM_H_INCLUDED_
8#define _NXT_RANDOM_H_INCLUDED_
9
10
11#if (NXT_HAVE_ARC4RANDOM)
12
13/*
14 * arc4random() has been introduced in OpenBSD 2.1 and then was ported
15 * to FreeBSD 2.2.6, NetBSD 2.0, MacOSX and SmartOS.
16 *
17 * arc4random() automatically initializes itself in the first call and
18 * then reinitializes itself in the first call in every forked processes.
19 */
20
21typedef void *nxt_random_t;
22
23
24#define nxt_random_init(r)
25#define nxt_random(r) arc4random()
26
27#else
28
11typedef struct {
12 uint8_t i;
13 uint8_t j;
14 uint8_t s[256];
15 int32_t count;
16} nxt_random_t;
17
18
19void nxt_random_init(nxt_random_t *r);
20uint32_t nxt_random(nxt_random_t *r);
21
22#if (NXT_LIB_UNIT_TEST)
23nxt_int_t nxt_random_unit_test(nxt_thread_t *thr);
24#endif
25
44#endif
26
46
27#endif /* _NXT_RANDOM_H_INCLUDED_ */