Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ran_array.h
Go to the documentation of this file.
1
2
3/*
4 Aleph_w
5
6 Data structures & Algorithms
7 version 2.0.0b
8 https://github.com/lrleon/Aleph-w
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2026 Leandro Rabindranath Leon
13
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31*/
32
33/* This program by D E Knuth is in the public domain and freely copyable
34 * AS LONG AS YOU MAKE ABSOLUTELY NO CHANGES!
35 * It is explained in Seminumerical Algorithms, 3rd edition, Section 3.6
36 * (or in the errata to the 2nd edition --- see
37 * http://www-cs-faculty.stanford.edu/~knuth/taocp.html
38 * in the changes to Volume 2 on pages 171 and following). */
39
40/* N.B. The MODIFICATIONS introduced in the 9th printing (2002) are
41 included here; there's no backwards compatibility with the original. */
42
43/* This version also adopts Brendan McKay's suggestion to
44 accommodate naive users who forget to call ran_start(seed). */
45
46/* If you find any bugs, please report them immediately to
47 * taocp@cs.stanford.edu
48 * (and you will be rewarded if the bug is genuine). Thanks! */
49
50/************ see the book for explanations and caveats! *******************/
51/************ in particular, you need two's complement arithmetic **********/
52
53/* the old C calling conventions are used here, for reasons of portability */
54
67# ifdef __cplusplus
68# define ALEPH_RAN_ARRAY_DEPRECATED \
69 [[deprecated("ran_array.h goes in 8.0.0; use the engines of <random> instead")]]
70extern "C" {
71# else
72# define ALEPH_RAN_ARRAY_DEPRECATED
73# endif
74
79
80/* the following routines are from exercise 3.6--15 */
81/* after calling ran_start, get new randoms by, e.g., "x=ran_arr_next()" */
82
88
95
99#define ran_arr_next() (*ran_arr_ptr >=0 ? *ran_arr_ptr++ : ran_arr_cycle())
100
101# ifdef __cplusplus
102}
103# endif
104
105# undef ALEPH_RAN_ARRAY_DEPRECATED
#define ALEPH_RAN_ARRAY_DEPRECATED
Definition ran_array.h:68
void ran_start(long seed)
Starts the generator with seed: do this before using it.
Definition ran_array.c:66
long ran_arr_cycle(void)
Makes a new batch of numbers and returns its first one: ran_arr_next() calls it when the batch runs o...
Definition ran_array.c:97
long * ran_arr_ptr
Points to the next number of the batch, or to -1 when the batch has run out.
Definition ran_array.c:58
ValueArg< size_t > seed
Definition testHash.C:53