1 |
d93979b7
|
Arnaud Dieumegard
|
|
2 |
|
|
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc
|
3 |
|
|
|
4 |
|
|
-- This file is part of VESTs (Vhdl tESTs).
|
5 |
|
|
|
6 |
|
|
-- VESTs is free software; you can redistribute it and/or modify it
|
7 |
|
|
-- under the terms of the GNU General Public License as published by the
|
8 |
|
|
-- Free Software Foundation; either version 2 of the License, or (at
|
9 |
|
|
-- your option) any later version.
|
10 |
|
|
|
11 |
|
|
-- VESTs is distributed in the hope that it will be useful, but WITHOUT
|
12 |
|
|
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13 |
|
|
-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14 |
|
|
-- for more details.
|
15 |
|
|
|
16 |
|
|
-- You should have received a copy of the GNU General Public License
|
17 |
|
|
-- along with VESTs; if not, write to the Free Software Foundation,
|
18 |
|
|
-- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 |
|
|
|
20 |
|
|
-- ---------------------------------------------------------------------
|
21 |
|
|
--
|
22 |
|
|
-- $Id: ch_19_random-b.vhd,v 1.3 2001-10-26 16:29:36 paw Exp $
|
23 |
|
|
-- $Revision: 1.3 $
|
24 |
|
|
--
|
25 |
|
|
-- ---------------------------------------------------------------------
|
26 |
|
|
|
27 |
|
|
library math;
|
28 |
|
|
|
29 |
|
|
package body random is
|
30 |
|
|
|
31 |
|
|
use math.math_real;
|
32 |
|
|
|
33 |
|
|
constant sample_seeds : seed_array(0 to 50)
|
34 |
|
|
:= ( 0 => (1, 1),
|
35 |
|
|
1 => (1919456777, 2006618587),
|
36 |
|
|
2 => (928906921, 476680813),
|
37 |
|
|
3 => (715788085, 762347824),
|
38 |
|
|
4 => (366002668, 1804336679),
|
39 |
|
|
5 => (1866585254, 247488051),
|
40 |
|
|
6 => (1342990589, 1539624735),
|
41 |
|
|
7 => (677313287, 1675609237),
|
42 |
|
|
8 => (644816519, 2026475269),
|
43 |
|
|
9 => (1654953611, 564421524),
|
44 |
|
|
10 => (1020104619, 712556314),
|
45 |
|
|
11 => (609798541, 1592526288),
|
46 |
|
|
12 => (1106087470, 1468242308),
|
47 |
|
|
13 => (1378844312, 646793513),
|
48 |
|
|
14 => (966261604, 481733031),
|
49 |
|
|
15 => (1407842093, 1316990206),
|
50 |
|
|
16 => (1705378215, 1930221363),
|
51 |
|
|
17 => (206887499, 1810320799),
|
52 |
|
|
18 => (1681633030, 2114795480),
|
53 |
|
|
19 => (71194926, 1642522201),
|
54 |
|
|
20 => (663275331, 1947299255),
|
55 |
|
|
21 => (224432387, 944962866),
|
56 |
|
|
22 => (1156075861, 1866435087),
|
57 |
|
|
23 => (1670357576, 1247152991),
|
58 |
|
|
24 => (846934138, 1673364736),
|
59 |
|
|
25 => (1972636955, 1404522710),
|
60 |
|
|
26 => (533484185, 592078395),
|
61 |
|
|
27 => (1989468008, 1409246301),
|
62 |
|
|
28 => (697086615, 1975145057),
|
63 |
|
|
29 => (111393259, 1673620688),
|
64 |
|
|
30 => (1352201163, 872947497),
|
65 |
|
|
31 => (1342844190, 877696585),
|
66 |
|
|
32 => (938770066, 1222894811),
|
67 |
|
|
33 => (1144599578, 661919919),
|
68 |
|
|
34 => (1750521407, 269946538),
|
69 |
|
|
35 => (457892500, 1256953520),
|
70 |
|
|
36 => (1678589945, 356027520),
|
71 |
|
|
37 => (1484458924, 2103068828),
|
72 |
|
|
38 => (1296978761, 2124096638),
|
73 |
|
|
39 => (1702642440, 1161000593),
|
74 |
|
|
40 => (1244690090, 2016422304),
|
75 |
|
|
41 => (1858682943, 1053836731),
|
76 |
|
|
42 => (1496964676, 701079294),
|
77 |
|
|
43 => (432696952, 602526767),
|
78 |
|
|
44 => (2097684438, 1264032473),
|
79 |
|
|
45 => (2115456834, 298917738),
|
80 |
|
|
46 => (432301768, 232430346),
|
81 |
|
|
47 => (1929812456, 758157910),
|
82 |
|
|
48 => (1655564027, 1062345086),
|
83 |
|
|
49 => (1116121051, 538424126),
|
84 |
|
|
50 => (844396720, 821616997) );
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
procedure init_fixed ( random_info : out random_info_record;
|
88 |
|
|
mean : in real ) is
|
89 |
|
|
begin
|
90 |
|
|
random_info.distribution := fixed;
|
91 |
|
|
random_info.mean := mean;
|
92 |
|
|
end procedure init_fixed;
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
procedure init_uniform ( random_info : out random_info_record;
|
96 |
|
|
lower_bound, upper_bound : in real;
|
97 |
|
|
seed : in seed_type ) is
|
98 |
|
|
begin
|
99 |
|
|
assert lower_bound <= upper_bound
|
100 |
|
|
report "init_uniform: lower_bound > upper_bound" severity failure;
|
101 |
|
|
random_info.distribution := uniform;
|
102 |
|
|
random_info.lower_bound := lower_bound;
|
103 |
|
|
random_info.upper_bound := upper_bound;
|
104 |
|
|
random_info.seed := seed;
|
105 |
|
|
end procedure init_uniform;
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
procedure init_exponential ( random_info : out random_info_record;
|
109 |
|
|
mean : in real;
|
110 |
|
|
seed : in seed_type ) is
|
111 |
|
|
begin
|
112 |
|
|
assert mean > 0.0
|
113 |
|
|
report "init_exponential: mean not positive" severity failure;
|
114 |
|
|
random_info.distribution := exponential;
|
115 |
|
|
random_info.mean := mean;
|
116 |
|
|
random_info.seed := seed;
|
117 |
|
|
end procedure init_exponential;
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
procedure generate_uniform ( random_info : inout random_info_record;
|
121 |
|
|
random_number : out real ) is
|
122 |
|
|
variable tmp : real;
|
123 |
|
|
begin
|
124 |
|
|
math_real.uniform(random_info.seed.seed1, random_info.seed.seed2, tmp);
|
125 |
|
|
random_number := random_info.lower_bound
|
126 |
|
|
+ tmp * (random_info.upper_bound - random_info.lower_bound);
|
127 |
|
|
end procedure generate_uniform;
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
procedure generate_exponential ( random_info : inout random_info_record;
|
131 |
|
|
random_number : out real ) is
|
132 |
|
|
variable tmp : real;
|
133 |
|
|
begin
|
134 |
|
|
loop
|
135 |
|
|
math_real.uniform(random_info.seed.seed1, random_info.seed.seed2, tmp);
|
136 |
|
|
exit when tmp /= 0.0;
|
137 |
|
|
end loop;
|
138 |
|
|
random_number := - random_info.mean * math_real.log(tmp);
|
139 |
|
|
end procedure generate_exponential;
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
procedure generate_random ( random_info : inout random_info_record;
|
143 |
|
|
random_number : out real ) is
|
144 |
|
|
begin
|
145 |
|
|
case random_info.distribution is
|
146 |
|
|
when fixed =>
|
147 |
|
|
random_number := random_info.mean;
|
148 |
|
|
when uniform =>
|
149 |
|
|
generate_uniform(random_info, random_number);
|
150 |
|
|
when exponential =>
|
151 |
|
|
generate_exponential(random_info, random_number);
|
152 |
|
|
end case;
|
153 |
|
|
end procedure generate_random;
|
154 |
|
|
|
155 |
|
|
end package body random;
|