comp.lang.ada
 help / color / mirror / Atom feed
* Building on Random_Float?
@ 2002-05-09 20:29 Mars Gralia
  2002-05-26 23:24 ` Robert I. Eachus
  0 siblings, 1 reply; 3+ messages in thread
From: Mars Gralia @ 2002-05-09 20:29 UTC (permalink / raw)


Ada Wizards and Gentle Folk,

I would like a high-level Ada95 design that allows me to build a
layered series of random number generators which ultimately use
Ada.Numerics.Float_Random.  Could you please provide me one?

Details are given below.

Thank you,
Mars Gralia, D.Sc.
The Johns Hopkins University
Applied Physics Laboratory
gralia@jhuapl.edu
443.778.5509 (USA)


Appendix A: Software Specification
Appendix B: Specification Amplification
Appendix C: Background
Appendix D: Desired Specification Files



----------------- Appendix A: Software Specification

10) The goal is a "package Interest_Rate_Pkg", which produces random
    numbers from a gamma distribution.
20) The "package specification", file Interest_Rate_Pkg.ads, differs
    form Ada.Numerics.Float_Random only
    a) in the package name and
    b) the data type Uniformly_Distributed
      b1)  declaration is eliminated
      b2)  is converted to "Float" for the "function Random".
30) The package is built in the following layers:
        package Interest_Rate_Pkg, which "withs"
          package General_Gamma_Pkg, which "withs"
            package Standard_Gamma_Pkg, which "withs"
              package Exponential_Pkg, which "withs"
                package Ada.Numerics.Float_Random;
              package Normal_Pkg, which "withs"
                package Ada.Numerics.Float_Random;
              package Ada.Numerics.Float_Random.
40) I am not requesting the algorithms, for I have all of them.  Indeed,
    they run with the uniform generator the author supplies.  But I
    prefer the Ada95 generator as the basis.





----------------- Appendix B: Specification Details

10) This note more carefully defines the family of generators I
    would like to use.  It's code skelton is:

    package Interest_Rate_Pkg is ... end Interest_Rate_Pkg;
    with General_Gamma_Pkg; package body Interest_Rate_Pkg is
      ...  end Interest_Rate_Pkg;

    package General_Gamma_Pkg is ... end General_Gamma_Pkg;
    with Standard_Gamma_Pkg; package body General_Gamma_Pkg is
      ... end General_Gamma_Pkg;

    package Standard_Gamma_Pkg is ... end Standard_Gamma_Pkg;
    with Normal_Pkg, Exponential_Pkg, Ada.Numerics.Float_Random;
    package body Standard_Gamma_Pkg is ... end Standard_Gamma_Pkg;

    package Exponential_Pkg is ... end Exponential_Pkg;
    with Ada.Numerics.Float_Random;  package body Exponential_Pkg is
      ... end Exponential_Pkg;

    package Normal_Pkg is ... end Normal_Pkg;
    with Ada.Numerics.Float_Random;  package body Normal_Pkg is
      ... end Normal_Pkg;

20) I would prefer the technology allow me to continue the
    layering even deeper than the four levels I need in this example.



----------------- Appendix C: Background

I'm working under Gnat 3.13p, but would like to use only standard
Ada.

I've tried, and failed:
a) To simply build the second layer on Ada.Numerics.Float_Random.
   As expected, this failed because Float_Random is a "limited private",
   so I can't use an assignment statement to store it in
   Normal_Pkg.Generator.
b) To make a package Ada.Numerics.Float_Random.Normal.  The
   specific message was:
   --> ada.numerics.float_random.random_brown_pkg.ads:1:01:
   --> current unit cannot depend on "Float_Random" (wrong
   --> categorization)
c) To use pointers as did Mr. Eachus in his ADAR_Random_Number.
   Hint: I got it from the Google archives.  It had the header:
   --> From: Robert I. Eachus (eachus@spectre.mitre.org)
   --> Subject: Re: Random number generators
   --> Newsgroups: comp.lang.ada
   --> Date: 1995/07/25

I feel I'm a journeyman programmer, certainly not a formal
student.  (But aren't we all still learning?)

The source of my current algorithm for all the layers are found in
http://odin.mdacc.tmc.edu/anonftp/page_2.html#RANDLIB They were
developed by Barry W. Brown, James Lovato, Kathy Russell and John
Venier.  On the web, it was called "randlib".  Internally, it is labeled
"RANDLIB; Library of Fortran Routines for Random Number Generation;
Version 1.3 -- August, 1997".  The authors are with the
> Department of Biomathematics, Box 237;
> The University of Texas, M.D. Anderson Cancer Center;
> 1515 Holcombe Boulevard;
> Houston, TX      77030
They also tell us "This work was supported by grant CA-16672 from the
National Cancer Institute."



----------------- Appendix D: Desired Specification Files

This section gives the package specs I'd like to have in the end.
Note they are virtually identical.

  package Interest_Rate_Pkg is
    type Generator is limited private;
    function Random (Gen: Generator) return Float;
    procedure Reset (Gen: in Generator; Initiator: in Integer);
    procedure Reset (Gen: in Generator);
    type State is private;
    procedure Save (Gen: in Generator; To_State: out State);
    procedure Reset (Gen: in Generator; From_State: in State);
    Max_Image_Width: constant := implementation-defined integer value;
    function Image (Of_State: State) return String;
    function Value (Coded_State: String) return State;
  private
    ... -- not specified by Gralia
  end Interest_Rate_Pkg;

  package General_Gamma_Pkg is
    type Generator is limited private;
    function Random (Gen: Generator) return Float;
    procedure Reset (Gen: in Generator; Initiator: in Integer);
    procedure Reset (Gen: in Generator);
    type State is private;
    procedure Save (Gen: in Generator; To_State: out State);
    procedure Reset (Gen: in Generator; From_State: in State);
    Max_Image_Width: constant := implementation-defined integer value;
    function Image (Of_State: State) return String;
    function Value (Coded_State: String) return State;
  private
    ... -- not specified by Gralia
  end General_Gamma_Pkg;

  package Standard_Gamma_Pkg is
    type Generator is limited private;
    function Random (Gen: Generator) return Float;
    procedure Reset (Gen: in Generator; Initiator: in Integer);
    procedure Reset (Gen: in Generator);
    type State is private;
    procedure Save (Gen: in Generator; To_State: out State);
    procedure Reset (Gen: in Generator; From_State: in State);
    Max_Image_Width: constant := implementation-defined integer value;
    function Image (Of_State: State) return String;
    function Value (Coded_State: String) return State;
  private
    ... -- not specified by Gralia
  end Standard_Gamma_Pkg;

  package Exponential_Pkg is
    type Generator is limited private;
    function Random (Gen: Generator) return Float;
    procedure Reset (Gen: in Generator; Initiator: in Integer);
    procedure Reset (Gen: in Generator);
    type State is private;
    procedure Save (Gen: in Generator; To_State: out State);
    procedure Reset (Gen: in Generator; From_State: in State);
    Max_Image_Width: constant := implementation-defined integer value;
    function Image (Of_State: State) return String;
    function Value (Coded_State: String) return State;
  private
    ... -- not specified by Gralia
  end Exponential_Pkg;

  package Normal_Pkg is
    type Generator is limited private;
    function Random (Gen: Generator) return Float;
    procedure Reset (Gen: in Generator; Initiator: in Integer);
    procedure Reset (Gen: in Generator);
    type State is private;
    procedure Save (Gen: in Generator; To_State: out State);
    procedure Reset (Gen: in Generator; From_State: in State);
    Max_Image_Width: constant := implementation-defined integer value;
    function Image (Of_State: State) return String;
    function Value (Coded_State: String) return State;
  private
    ... -- not specified by Gralia
  end Normal_Pkg;


(end of note)



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Building on Random Float?
@ 2002-05-10 19:36 Mike Brenner
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Brenner @ 2002-05-10 19:36 UTC (permalink / raw)


> ... as did Mr. Eachus in his ADAR_Random_Number ... Hint: I got it from the Google archives. It had the header: From: Robert I. Eachus (eachus@spectre.mitre.org) ...


I just retired the spectre server, but I save the eachus archives on a CD. Does anyone know Bob Eachus' current email address?

Mike Brenner




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Building on Random_Float?
  2002-05-09 20:29 Building on Random_Float? Mars Gralia
@ 2002-05-26 23:24 ` Robert I. Eachus
  0 siblings, 0 replies; 3+ messages in thread
From: Robert I. Eachus @ 2002-05-26 23:24 UTC (permalink / raw)


Mars Gralia wrote:

> Ada Wizards and Gentle Folk,
> 
> I would like a high-level Ada95 design that allows me to build a
> layered series of random number generators which ultimately use
> Ada.Numerics.Float_Random.  Could you please provide me one?
> 
> Details are given below.


I guess I don't see your problem.  Generators are and should be limited, 
because of the mischief that can come from making a copy of one.  (The 
mechanism for states insures that you can save, copy, etc. generator 
states, but that random sequences from a generator have guaranteed 
properties between resets.

But there is nothing to prevent you from creating a normal generator 
that is also limited with a uniform generator (or two) as components.
I say or two because the best normal distribution generator I know uses 
two uniform variates.  But remember if you do use two generators, to get 
full benefit, you need to initialize (reset) them using different 
sources of randomness.

My current email address is rieachus@attbi.com.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-05-26 23:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-09 20:29 Building on Random_Float? Mars Gralia
2002-05-26 23:24 ` Robert I. Eachus
  -- strict thread matches above, loose matches on Subject: below --
2002-05-10 19:36 Building on Random Float? Mike Brenner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox