comp.lang.ada
 help / color / mirror / Atom feed
* Re: Source for Random Number Generator
       [not found] <5d8b95$oec@zeus.orl.mmc.com>
@ 1997-02-07  0:00 ` Nigel J. Tracey
  1997-02-10  0:00   ` Jeff Carter
       [not found] ` <EACHUS.97Feb6161130@spectre.mitre.org>
       [not found] ` <19970206153301.KAA04399@ladder01.news.aol.com>
  2 siblings, 1 reply; 6+ messages in thread
From: Nigel J. Tracey @ 1997-02-07  0:00 UTC (permalink / raw)
  To: kcronin


In article <5d8b95$oec@zeus.orl.mmc.com>,
	kcronin@unconfigured.xvnews.domain (Kevin Cronin) writes:
>Does anyone have some quick & dirty Ada source for a 
>random number generator that returns a float in the range 0.1 .. 1.0?
>Thanks.
>
>

Try from the Ada.Numerics.Random package implemenation in Gnat in the
file a-numran.adb in the adainclude directory. This is between 0.0 and
1.0, not sure if that is important for you.

Nigel






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

* Re: Source for Random Number Generator
       [not found] ` <EACHUS.97Feb6161130@spectre.mitre.org>
@ 1997-02-07  0:00   ` Robert I. Eachus
  1997-02-10  0:00     ` VADSWorks X-Debugger Michael Levasseur
  0 siblings, 1 reply; 6+ messages in thread
From: Robert I. Eachus @ 1997-02-07  0:00 UTC (permalink / raw)




   Following up my own posting, how gauche.  Oh, well I didn't want to
mislead anyone...

  >  with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
  >  function Biased_Random(Gen: in Generator) return Float is
  >  begin
  >    return Random(Gen) * 0.9 + 0.1;
  >  end Biased_Random;

  Ask for quick and dirty and get it.  I probably should have put a
smiley face on this.

  >    Now if you will settle for not so quick and dirty, I would
  > recommend:

  >  with Ada.Numerics.Float_Random;
  >  generic
  >    type Result_Type is digits <>;
  >    Gen: in out Ada.Numerics.Float_Random.Generator;
  >  function Generalized_Random return Result_Type;

  Do not instantiate this with an unconstrained floating-point type.
It will break, and I can see no reason slow things down to deal with
such a bogus choice.  But I probably should have put in a comment.

  >   function Generalized_Random return Result_Type is
  >	Temp: Result_Type;
  >   begin
  >     Temp := Result_Type(Float(Result_Type'First) +
  >	       Float(Result_Type'Last-Result_Type'First) * 
  >	       Ada.Numerics.Float_Random.Random(Gen));
  >	return Temp;
-- Temp is only used for expository purposes. On some hardware it may
-- be better to just say:
  >     return Result_Type(Float(Result_Type'First) +
  >	       Float(Result_Type'Last-Result_Type'First) * 
  >	       Ada.Numerics.Float_Random.Random(Gen));
-- But it depends on your compiler's inlining policy.
  >   exception when others => return Generalized_Random;
  >   -- rounding errors can result in a value of Temp outside the result
  >   -- subtype when the bounds are not model numbers.
  >   end Generalized_Random;

-- This comment is technically not true if the compiler doesn't
-- support the numerics annex or you are not running in strict mode.
-- But you still want the exception handler there.

      with Ada.Numerics.Float_Random; with Generalized_Random; with Text_IO;
      procedure Test_GR is
	subtype Result_Subtype is Float range 0.1..1.0;
	My_Gen: Ada.Numerics.Float_Random.Generator;
	function Rand is new Generalized_Random(Result_Subtype, My_Gen);
-- add pragma Inline for Rand here.
	package Floating_IO is new Text_IO.Float_IO(Result_Subtype);
      begin
	Text_IO.New_Line;
	for I in 1..10 loop
	  for J in 1..6 loop
	    Floating_IO.Put(Rand,3,9,0);
	  end loop;
	  Text_IO.New_Line;
	end loop;
      end Test_GR;

--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




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

* Re: Source for Random Number Generator
       [not found] ` <19970206153301.KAA04399@ladder01.news.aol.com>
@ 1997-02-08  0:00   ` Robert I. Eachus
  1997-02-11  0:00     ` johnherro
  0 siblings, 1 reply; 6+ messages in thread
From: Robert I. Eachus @ 1997-02-08  0:00 UTC (permalink / raw)



In article <19970206153301.KAA04399@ladder01.news.aol.com> johnherro@aol.com writes:

 > The only guarantees are that it IS quick and it IS dirty!  It'll
 > work in Ada 83 as well as Ada 95.  Some mathematicians out there
 > will undoubtedly be able to improve on this:

   With a disclaimer like that from John, I can't be TOO hard on him,
but...this sequence is anything but random.   I can cite dozens of
papers on the problems with LCGs, especially those with short periods
and small multipliers.  If you want to see the problem with this
generator grapically, write a program that graphs the data.  Either
take pairs of numbers and use them as x and y coordinate values or
better plot triples in three dimensions.  Everything will line up in
lines or planes, with large empty spaces in between.

  Some of the other generators that have been posted here are somewhat
better, but only somewhat.  I wouldn't use any of them to choose what
I was going to have for dinner. ;-)

   If anyone wants to get serious about this, I have a set of tests
I'll send them the source of.  But the easiest thing to do is to use
the generator built into GNAT.  I could go into lots of gory details,
but just say that there are lots of tests of randomness it can be
proven will not fail, and there are lots of tests obvious and subtle
that I have run against it.  It works.  Well if you need more than
about 10 million random values per run talk to me.  That is
approaching the point where the theoretical proofs no longer apply,
and is the limit of the testing I have done.
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




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

* Re: Source for Random Number Generator
  1997-02-07  0:00 ` Source for Random Number Generator Nigel J. Tracey
@ 1997-02-10  0:00   ` Jeff Carter
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff Carter @ 1997-02-10  0:00 UTC (permalink / raw)



I guess no one else is going to mention the "universal random number
generator." This has a very long period and is reputedly very good
quality. See _Ada Letters_, 1988 Sep/Oct for Ada-83 source. It's uniform
in 0.0 .. 1.0 - 2 ** (-24), so some fiddling is necessary if you really
want 0.1 .. 1.0
-- 
Jeff Carter
Innovative Concepts, Inc.

Now go away, or I shall taunt you a second time.




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

* VADSWorks X-Debugger
  1997-02-07  0:00   ` Robert I. Eachus
@ 1997-02-10  0:00     ` Michael Levasseur
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Levasseur @ 1997-02-10  0:00 UTC (permalink / raw)



Hello,

I'm using VADSWorks on a System with SunOS. I'm having problems with 
the X-Debugger. I'm trying to use a custom resource file. I've
created a new resource file and I'm trying to make it take effect
when I kick off the debugger.

My debugger command is:

a.xdb -N baja4 gp_exec_4.vox

where baja4 is the Heurikon Baja board I'm debugging on.

gp_exec_4.vox is my executable.

My XAPPLRESDIR environment variable is

setenv XAPPLRESDIR /home/users/michael/drivers

This is where my copy of the resource file "Xdb" is located. This
is also the location I start my debug session in.

Thanx in advance for any suggestions...




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

* Re: Source for Random Number Generator
  1997-02-08  0:00   ` Source for Random Number Generator Robert I. Eachus
@ 1997-02-11  0:00     ` johnherro
  0 siblings, 0 replies; 6+ messages in thread
From: johnherro @ 1997-02-11  0:00 UTC (permalink / raw)



 eachus@spectre.mitre.org (Robert I. Eachus) writes:
> ...this sequence is anything but random....  If you want
> to see the problem [graph] the data.  Either take pairs
> of numbers and use them as x and y coordinate values
> or better plot triples in three dimensions.  Everything will
> line up in lines or planes, with large empty spaces in
> between.

You're right; the autocorrelation function is really atrocious.  Of
course, the random number generator built into an Ada 95 compiler is
likely to be much better, but I assume the original poster, Kevin Cronin,
wanted to see source, or perhaps he was asking because he has an Ada 83
compiler.

I vaguely remember reading a long time ago about how great is the power
residue method of generating pseudo-random numbers, but I never checked
the autocorrelation.  If Kevin really needs source, maybe we could
continue this discussion further and try other schemes, like multiplying
two large numbers and keeping the *middle* (instead of the low end, as in
the power residue method).  I'm sure some mathematicians out there can
come up with some really good source.

- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor






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

end of thread, other threads:[~1997-02-11  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <5d8b95$oec@zeus.orl.mmc.com>
1997-02-07  0:00 ` Source for Random Number Generator Nigel J. Tracey
1997-02-10  0:00   ` Jeff Carter
     [not found] ` <EACHUS.97Feb6161130@spectre.mitre.org>
1997-02-07  0:00   ` Robert I. Eachus
1997-02-10  0:00     ` VADSWorks X-Debugger Michael Levasseur
     [not found] ` <19970206153301.KAA04399@ladder01.news.aol.com>
1997-02-08  0:00   ` Source for Random Number Generator Robert I. Eachus
1997-02-11  0:00     ` johnherro

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