comp.lang.ada
 help / color / mirror / Atom feed
* Ada.Numerics.Float_Random.Generator question
@ 2016-09-17 19:40 Andrew Shvets
  2016-09-17 20:09 ` J-P. Rosen
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Andrew Shvets @ 2016-09-17 19:40 UTC (permalink / raw)


Hello,

If I want a random float number to be generated, the way that I did this in the past was something along these lines:

  function Create_Random_Float(
    From : in Float;
    To : in Float)
      return Float is

    Seed : Ada.Numerics.Float_Random.Generator;
  begin
    Ada.Numerics.Float_Random.Reset(Seed);

    return From + (Ada.Numerics.Float_Random.Random(Seed) * To);
  end Create_Random_Float;

This works.  However, as I'm now looking into the Ada.Numerics.Discrete_Random package, I've noticed that it can generate a random value based on the type that is passed in.  This appeals to me and I'd like to do the same for a custom float type (say I want the delta to be 0.01.)

As Ada.Numerics.Float_Random.Generator is not a generic package, I can't use the same approach.  The best way that I can think of is to create the same result using From and To and then cast the result to the custom float type.

I hope that there is a better solution to this.  Is there?


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

end of thread, other threads:[~2016-10-01 16:44 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-17 19:40 Ada.Numerics.Float_Random.Generator question Andrew Shvets
2016-09-17 20:09 ` J-P. Rosen
2016-09-17 20:14   ` Andrew Shvets
2016-09-17 21:01 ` Jeffrey R. Carter
2016-09-17 23:53   ` Andrew Shvets
2016-09-19 19:07 ` rieachus
2016-09-25 23:41 ` brbarkstrom
2016-09-26 13:04   ` Robert Eachus
2016-09-26 18:48     ` brbarkstrom
2016-09-29  9:42       ` Some Dude
2016-10-01  3:35         ` Robert Eachus
2016-10-01  3:59           ` Paul Rubin
2016-10-01 14:23             ` Robert Eachus
2016-10-01 15:49               ` Dmitry A. Kazakov
2016-10-01 16:44                 ` Robert Eachus

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