File: gnu_multiple_precision-random_numbers.ads

package info (click to toggle)
libgmpada 0.0.20131223-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 576 kB
  • ctags: 48
  • sloc: ada: 5,115; ansic: 118; makefile: 117; sed: 45; sh: 20
file content (100 lines) | stat: -rw-r--r-- 4,028 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
--    GMPAda, binding to the Ada Language for the GNU MultiPrecision library.
--    Copyright (C) 2007-2010 Nicolas Boulenguez <nicolas.boulenguez@free.fr>
--
--    This program is free software: you can redistribute it and/or modify
--    it under the terms of the GNU General Public License as published by
--    the Free Software Foundation, either version 3 of the License, or
--    (at your option) any later version.
--
--    This program is distributed in the hope that it will be useful,
--    but WITHOUT ANY WARRANTY; without even the implied warranty of
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--    GNU General Public License for more details.
--
--    You should have received a copy of the GNU General Public License
--    along with this program.  If not, see <http://www.gnu.org/licenses/>.

package GNU_Multiple_Precision.Random_Numbers is

   pragma Elaborate_Body;

   type Generator is limited private;
   --  No need for Stream attributes for this type.
   --  Use Save, Reset and Big_Integer instead.

   procedure Random (Result : in out Big_Integer;
                     Gen    : in out Generator;
                     Modulo : in     Natural);
   --  For usual needs, the default Ada.Random is enough.
   procedure Random (Result : in out Big_Integer;
                     Gen    : in out Generator;
                     Modulo : in     Big_Integer);
   procedure Random_2exp (Result : in out Big_Integer;
                          Gen    : in out Generator;
                          Count  : in     Bit_Count);

   procedure Random_2exp (Result : in out Big_Float;
                          Gen    : in out Generator;
                          Count  : in     Bit_Count);
   --  0.0 <= Mantissa <1.0

   procedure Reset (Gen       : in out Generator;
                    Initiator : in     Integer);
   procedure Reset (Gen       : in out Generator;
                    Initiator : in     Big_Integer);
   procedure Reset (Gen : in out Generator);

   type State is private;
   --  No Stream attributes for this type.
   --  Use Big_Integer instead.

   procedure Save (Gen      : in     Generator;
                   To_State :    out State);
   procedure Reset (Gen        : in out Generator;
                    From_State : in     State);

   procedure Reset_Mersenne_Twister (Gen : in out Generator);
   procedure Reset_Linear_Congruential (Gen   : in out Generator;
                                        A     : in     Big_Integer;
                                        C     : in     Natural;
                                        M2exp : in     Bit_Count);
   procedure Reset_Linear_Congruential_2exp_Size
     (Gen            : in out Generator;
      Size           : in     Natural;
      Found_In_Table :    out Boolean);
   procedure Generate_Corner_Case_Random_Bytes
     (Rop   : in out Big_Integer;
      Gen   : in out Generator;
      Count : in     Bit_Count);
   --  Generate a random integer with long strings of zeros and ones
   --  in the binary representation.  Useful for testing functions and
   --  algorithms, since this kind of random numbers have proven to be
   --  more likely to trigger corner-case bugs.

private

   type State is new Ada.Finalization.Controlled with record
      Value : GMP.Binding.Gmp_Randstate_T;
   end record;

   overriding procedure Initialize (Object : in out State);
   overriding procedure Adjust     (Object : in out State);
   overriding procedure Finalize   (Object : in out State);

   type Generator is limited record
      Gen_State : State;
   end record;

   pragma Inline (Adjust);
   pragma Inline (Finalize);
   pragma Inline (Generate_Corner_Case_Random_Bytes);
   pragma Inline (Initialize);
   pragma Inline (Random);
   pragma Inline (Random_2exp);
   pragma Inline (Reset);
   pragma Inline (Reset_Linear_Congruential);
   pragma Inline (Reset_Linear_Congruential_2exp_Size);
   pragma Inline (Reset_Mersenne_Twister);
   pragma Inline (Save);

end GNU_Multiple_Precision.Random_Numbers;