2
* ExtRandom - Additional randomization operations
3
* Copyright (C) 1996 Damien Doligez
4
* 2009 David Teller, LIFO, Universite d'Orleans
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version,
11
* with the special exception on linking described in file LICENSE.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
let full_init = full_init
28
let self_init = self_init
33
let nativeint = nativeint
37
let char () = Char.chr (int 256)
42
include State (*Note: here, we use [Marshal] to avoid breaking abstraction. So it's not portable.*)
44
let char t = Char.chr (int t 256)
46
(**A constructor for enumerations of random numbers taking advantage
47
of [State] to allow cloning.*)
48
let random_enum state next =
50
let next () = next state in
51
let count () = raise BatEnum.Infinite_enum in
52
let clone () = aux ( State.copy state ) in
53
BatEnum.make next count clone
56
let enum_bits state () =
57
let next state = bits state in
58
random_enum state next
60
let enum_int state bound =
61
let next state = int state bound in
62
random_enum state next
64
let enum_int32 state bound =
65
let next state = int32 state bound in
66
random_enum state next
68
let enum_int64 state bound =
69
let next state = int64 state bound in
70
random_enum state next
72
let enum_float state bound =
73
let next state = float state bound in
74
random_enum state next
76
let enum_nativeint state bound =
77
let next state = nativeint state bound in
78
random_enum state next
80
let enum_bool state () =
81
let next state = bool state in
82
random_enum state next
84
let enum_char state () =
85
let next state = char state in
86
random_enum state next
90
let random_enum next = State.random_enum ( State.make_self_init () ) next
93
let next state = State.bits state in
97
let next state = State.int state bound in
100
let enum_int32 bound =
101
let next state = State.int32 state bound in
104
let enum_int64 bound =
105
let next state = State.int64 state bound in
108
let enum_float bound =
109
let next state = State.float state bound in
112
let enum_nativeint bound =
113
let next state = State.nativeint state bound in
117
let next state = State.bool state in
121
let next state = State.char state in
125
let a = BatArray.of_enum e in
126
let len = Array.length a in
127
Array.get a (int len)
130
let a = BatArray.of_enum e in
131
for n = Array.length a - 1 downto 1 do
132
let k = int ( n + 1 ) in
134
let buf = Array.get a n in
135
Array.set a n (Array.get a k);
140
let get_state = get_state
141
let set_state = set_state