Aleph-w
3.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
55
# ifdef __cplusplus
56
extern
"C"
{
57
# endif
58
59
60
61
/*
62
do this before using ran_array
63
*/
64
extern
void
ran_start
(
long
seed);
65
66
67
/* the following routines are from exercise 3.6--15 */
68
/* after calling ran_start, get new randoms by, e.g., "x=ran_arr_next()" */
69
70
extern
long
*
ran_arr_ptr
;
/* the next random number, or -1 */
71
72
extern
long
ran_arr_cycle
(
void
);
73
74
#define ran_arr_next() (*ran_arr_ptr >=0 ? *ran_arr_ptr++ : ran_arr_cycle())
75
76
# ifdef __cplusplus
77
}
78
# endif
79
80
81
82
83
ran_start
void ran_start(long seed)
Definition
ran_array.c:66
ran_arr_cycle
long ran_arr_cycle(void)
Definition
ran_array.c:97
ran_arr_ptr
long * ran_arr_ptr
Definition
ran_array.c:58
ran_array.h
Generated by
1.9.8