From: Andrew <eagletalon@chartermi.net>
Subject: Re: random number generation
Date: Fri, 26 Sep 2003 14:25:12 -0500
Date: 2003-09-26T14:25:12-05:00 [thread overview]
Message-ID: <vn94lrbrcr6m38@corp.supernews.com> (raw)
In-Reply-To: <O_Rcb.340899$2x.104289@rwcrnsc52.ops.asp.att.net>
tmoran@acm.org wrote:
>>I need to write a program to randomly grab a integer from 1 - 4,and
>>Does this exist in Ada?
>
> type Options is range 1 .. 4;
> package Generate_Options is new Ada.Numerics.Discrete_Random(Options);
> A_Generator : Generate_Options.Generator;
> ...
> X := Generate_Options.Random(A_Generator);
> Ada.Text_IO.Put_Line("Selected option is" & Options'image(X));
> You could of course replace type Options with
> type Suits is (Spades, Hearts, Diamonds, Clubs);
> and have several Dealers instead of a single A_Generator, and so forth.
>
>
>> I don't believe it does from what I have been reading.
>
> What have you been reading? If your book doesn't cover random
> number generation, you can go to the authoritative source, section
> A.5.2 of the Ada 95 Reference Manual (available online).
ok in the previous post .. I said thanks for the help.. and I've been
trying to figure out how to implement the code that you gave me above..
the problem is I get errors such as
mazecreate.adb:18:04: statement not allowed in declarative part
or
mazecreate.adb:26:01: declarations must come before "begin"
depending on exactly how I set the code up.
here is the coding at it's current standing.
========================================
====================================
-- This program is to open file 'Map2', then print a bunch of characters
'x' in the
-- form of a square.
with TEXT_IO;
use TEXT_IO;
procedure Mazecreate is
spot: CHARACTER:='x';
spott: CHARACTER:='T';
sitt: Boolean:=True;
orig: INTEGER:=5; -- point of origin for map
down: Integer:=10; -- down map
acros: INTEGER:=11; -- across map
row: INTEGER:=1;
col: INTEGER:=1;
X: INTEGER;
map_file:FILE_TYPE;
A_Generator : Generate_Options.Generator;
X:= Generator_Options.Random(A_Generator);
package Number_IO is new INTEGER_IO(INTEGER);
use Number_IO;
package FLOAT1_IO is new FLOAT_IO(FLOAT);
use FLOAT1_IO;
type Options is range 1 .. 4;
package Generate_Options is new
Ada.Numerics.Discrete_Random(Options);
Begin
-- **********************
-- ** section to print **
-- ** the randomly **
-- ** created number **
-- **********************
Ada.Text_IO.Put_Line("Selected option is" & Options'image(X));
-- *********************
-- ** section to **
-- ** create the **
-- ** square of Stars **
-- *********************
Create (map_file, out_FILE, "Map2");
if IS_OPEN(map_file) then
for i in 1..down loop
for j in 1..acros loop
put (map_file, spot);
end loop;
NEW_LINE(map_file);
end loop;
Put(map_file, spott);
CLOSE (map_file);
else
Put_Line("Map file didn't open .. Killing Program");
Return;
end if;
end Mazecreate;
==============================
===============================================
Now I know I have something wrong on the above code.. but I can't figure
out what is wrong.. and I've tried moving different sections of your
code around.. but to no avail.
any help is appreciated.
Andrew
next prev parent reply other threads:[~2003-09-26 19:25 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-26 7:00 random number generation Andrew
2003-09-26 7:35 ` tmoran
2003-09-26 17:58 ` Andrew
2003-09-26 19:25 ` Andrew [this message]
2003-09-26 19:35 ` chris
2003-09-26 21:44 ` tmoran
2003-09-27 1:40 ` Robert I. Eachus
2003-09-27 4:48 ` Andrew
-- strict thread matches above, loose matches on Subject: below --
2010-12-30 10:43 Random " Mart van de Wege
2010-12-30 10:54 ` Thomas Løcke
2010-12-30 12:11 ` Mart van de Wege
2010-12-30 11:34 ` Niklas Holsti
2010-12-30 11:53 ` Georg Bauhaus
2010-12-30 12:25 ` Mart van de Wege
2010-12-30 15:29 ` Georg Bauhaus
2010-12-30 15:37 ` Mart van de Wege
2010-12-30 11:51 ` Brian Drummond
2010-12-30 12:16 ` Mart van de Wege
2010-12-30 13:04 ` Dmitry A. Kazakov
2010-12-30 13:22 ` Niklas Holsti
2010-12-30 13:39 ` Dmitry A. Kazakov
2010-12-30 13:30 ` Mart van de Wege
2010-12-31 3:14 ` Gene
2010-07-13 12:45 tonyg
2010-07-13 12:50 ` Jacob Sparre Andersen
2010-07-13 12:58 ` Dmitry A. Kazakov
2010-07-13 13:17 ` Thomas Løcke
2010-07-13 16:07 ` Jeffrey R. Carter
2010-07-13 20:33 ` John B. Matthews
2010-07-13 23:02 ` Jeffrey R. Carter
2010-07-14 4:42 ` John B. Matthews
2010-07-15 19:01 ` tonyg
2003-09-26 7:14 random " christoph.grein
1997-12-19 0:00 Mok-kong Shen
1998-01-02 0:00 ` Mok-kong Shen
1998-01-02 0:00 ` Robert Dewar
1996-10-13 0:00 Random Number Generation parker
1996-10-13 0:00 ` Robert Dewar
1996-10-14 0:00 ` Robert A Duff
1996-10-10 0:00 Dr J Parker
1996-10-12 0:00 ` Geert Bosch
1996-10-12 0:00 ` Keith Thompson
1996-10-10 0:00 Dr J Parker
1996-10-02 0:00 Dr J Parker
1996-10-03 0:00 ` Mats Weber
1996-10-07 0:00 ` Geert Bosch
1996-09-23 0:00 Nigel J. Tracey
1996-09-23 0:00 ` Tucker Taft
1996-10-02 0:00 ` Nigel J. Tracey
1996-10-02 0:00 ` Robert I. Eachus
1996-10-03 0:00 ` Nigel J. Tracey
1996-09-25 0:00 ` James_Rogers
1996-09-26 0:00 ` Dale Stanbrough
1996-10-01 0:00 ` Robert I. Eachus
1996-09-30 0:00 ` Dr J Parker
1996-10-01 0:00 ` Tucker Taft
1996-10-01 0:00 ` Keith Thompson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox