comp.lang.ada
 help / color / mirror / Atom feed
* Stream_Access value valid across Close/Open?
@ 1997-09-30  0:00 Dale Stanbrough
  1997-09-30  0:00 ` Random Number problems David Muhammad
  0 siblings, 1 reply; 5+ messages in thread
From: Dale Stanbrough @ 1997-09-30  0:00 UTC (permalink / raw)



Is an Ada.Streams.Stream_IO.Stream_Access value valid across calls
to Close/Open of the associated File variable? The LRM is silent
on this issue, but I would guess not. Gnat 3.09 lets me do it,
but I suspect this falls into the realm of "erroneous behaviour".


Dale




^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: Random Number problems
@ 1997-10-01  0:00 John Herro
  0 siblings, 0 replies; 5+ messages in thread
From: John Herro @ 1997-10-01  0:00 UTC (permalink / raw)



David Muhammad <guru@activist.com> writes:
> I have written the Random Number Generator
> function but how do I tell the compiler to
> select a number between 1and 52?

It depends on what your function Rand_Num returns.  Suppose Rand_Num
returns a Float between 0.0 and 1.0.  Then the following should work in
both Ada 95 and Ada 83.  If you have "subtype Pseudorand is Integer range 1
.. 52;" and you declare "P : Pseudorand;", you could write

P := Pseudorand(Rand_Num*52.0 + 0.5);

The expression within the parentheses is a Float.  When Ada converts a
Float to an integer type, it rounds.  That's why I added 0.5 and not 1.0. 
If Rand_Num is just above 0.0, P will be 1, and if Rand_Num is just below
1.0, P will be 52.

With some Ada compilers, it's not certain which way it will round if the
fractional part of the Float is exactly 0.5.  So if your Rand_Num function
might return exactly 0.0 or 1.0, you may have to add code to check that the
result of rounding is between 1 and 52 before storing in P.  (E.g., if the
result is 0, force it to 1 before storing, and force a result of 53 to 52.)
 I hope this helps.

- John Herro
Download the shareware Ada Tutor program at
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-09-30  0:00 Stream_Access value valid across Close/Open? Dale Stanbrough
1997-09-30  0:00 ` Random Number problems David Muhammad
1997-10-01  0:00   ` Martin C. Carlisle
1997-10-01  0:00   ` Geert Bosch
  -- strict thread matches above, loose matches on Subject: below --
1997-10-01  0:00 John Herro

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