1 |
3 |
mgeng |
----------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
|
|
---- Auxiliary package with mathematical functions. ----
|
4 |
|
|
---- ----
|
5 |
|
|
---- This file is part of the simu_mem project ----
|
6 |
|
|
---- ----
|
7 |
|
|
---- Authors: ----
|
8 |
|
|
---- - Michael Geng, vhdl@MichaelGeng.de ----
|
9 |
|
|
---- ----
|
10 |
|
|
----------------------------------------------------------------------
|
11 |
|
|
---- ----
|
12 |
|
|
---- Copyright (C) 2008 Authors ----
|
13 |
|
|
---- ----
|
14 |
|
|
---- This source file may be used and distributed without ----
|
15 |
|
|
---- restriction provided that this copyright statement is not ----
|
16 |
|
|
---- removed from the file and that any derivative work contains ----
|
17 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
18 |
|
|
---- ----
|
19 |
|
|
---- This source file is free software; you can redistribute it ----
|
20 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
21 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
22 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
23 |
|
|
---- later version. ----
|
24 |
|
|
---- ----
|
25 |
|
|
---- This source is distributed in the hope that it will be ----
|
26 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
27 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
28 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
29 |
|
|
---- details. ----
|
30 |
|
|
---- ----
|
31 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
32 |
|
|
---- Public License along with this source; if not, download it ----
|
33 |
|
|
---- from http://www.gnu.org/licenses/lgpl.html ----
|
34 |
|
|
---- ----
|
35 |
|
|
----------------------------------------------------------------------
|
36 |
|
|
-- CVS Revision History
|
37 |
|
|
--
|
38 |
|
|
-- $Log: not supported by cvs2svn $
|
39 |
|
|
--
|
40 |
|
|
PACKAGE math_pkg IS
|
41 |
|
|
-- linear congruential generator (a random number generator)
|
42 |
|
|
-- use result for the seed in the next call
|
43 |
|
|
-- preferably use bits 30...16
|
44 |
|
|
FUNCTION lcg (seed : IN NATURAL) RETURN NATURAL;
|
45 |
|
|
END PACKAGE math_pkg;
|
46 |
|
|
|
47 |
|
|
PACKAGE BODY math_pkg IS
|
48 |
|
|
FUNCTION lcg (seed : IN NATURAL) RETURN NATURAL IS
|
49 |
|
|
-- Constants from: http://en.wikipedia.org/wiki/Linear_congruential_generator
|
50 |
|
|
CONSTANT a : NATURAL := 16807;
|
51 |
|
|
CONSTANT c : NATURAL := 0;
|
52 |
|
|
CONSTANT m : NATURAL := 2 ** 31 - 1;
|
53 |
|
|
BEGIN
|
54 |
|
|
RETURN (a * seed + c) MOD m;
|
55 |
|
|
END FUNCTION;
|
56 |
|
|
END PACKAGE BODY math_pkg;
|