[go: up one dir, main page]

File: random.h

package info (click to toggle)
cctools 1%3A7.15.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,008 kB
  • sloc: ansic: 117,215; python: 30,569; cpp: 20,301; sh: 13,834; perl: 4,056; xml: 3,688; makefile: 1,502
file content (68 lines) | stat: -rw-r--r-- 1,358 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright (C) 2022 The University of Notre Dame
 * This software is distributed under the GNU General Public License.
 * See the file COPYING for details.
 */

#ifndef RANDOM_H
#define RANDOM_H

#include <stdint.h>
#include <stdlib.h>

/** @file random.h A PRNG library.
 */

/** Initialize the random number generator.
 *
 * Uses system PRNG devices to seed the library PRNG.
 */
void    random_init (void);

/** Get a random int.
 *
 * @return a random int.
 */
#define random_int()   ((int) random_int64())

/** Get a random unsigned int.
 *
 * @return a random unsigned int.
 */
#define random_uint()   ((unsigned) random_int64())

/** Get a random int32_t.
 *
 * @return a random int32_t.
 */
#define random_int32() ((int32_t) random_int64())

/** Get a random int64_t.
 *
 * @return a random int64_t.
 */
int64_t random_int64 (void);

/** Get a random double from (0, 1)
 *
 * @return a random double from (0, 1)
 */
double random_double (void);

/** Insert random data into an array.
 *
 * @param m the memory to fill.
 * @param l the length of the m.
 */
void    random_array (void *m, size_t l);

/** Insert a random string in hexadecimal.
 *
 * @param s the location in the string.
 * @param l the number of characters to insert. Includes NUL byte!
 */
void    random_hex   (char *s, size_t l);

#endif

/* vim: set noexpandtab tabstop=8: */