comp.lang.ada
 help / color / mirror / Atom feed
* How do you randomise integers?
@ 1997-05-16  0:00 the AJE
  1997-05-19  0:00 ` Michael F Brenner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: the AJE @ 1997-05-16  0:00 UTC (permalink / raw)



I have only just begun learning ADA, but I can't find a book with decent
examples on randomising numbers.  I could try using C++, but I much prefer
ADA.  The biggest problem is finding something to connect the randomizer to
the timer so that a different seed is used everytime the programme is run. 
I would appreciate some examples using dice-rolls etc. because I can't
decipher syntaxes very well.

Thanks in advanced.
Andrew.




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

* Re: How do you randomise integers?
  1997-05-16  0:00 How do you randomise integers? the AJE
@ 1997-05-19  0:00 ` Michael F Brenner
  1997-05-20  0:00 ` Nick Roberts
  1997-05-20  0:00 ` Jon S Anthony
  2 siblings, 0 replies; 4+ messages in thread
From: Michael F Brenner @ 1997-05-19  0:00 UTC (permalink / raw)



You said you could do it in C++. That would make it very easy in Ada,
because we could either (1) call the C++ or (2) translate the C++
into Ada. Could you post the C++ code that reads the system clock,
converts it to a set of integers you have declared? Seeding the
random number generator is just a matter of storing those integers
into an array 

The ++ could be your Program Design Language for the Ada code. THen
just substitute a call to the Ada clock and the Ada random number
generation setter (reset).

Or we could program our own random number generator and try to make it
pass the stringent Bob Eachustests.

Obviously you can




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

* Re: How do you randomise integers?
  1997-05-16  0:00 How do you randomise integers? the AJE
  1997-05-19  0:00 ` Michael F Brenner
@ 1997-05-20  0:00 ` Nick Roberts
  1997-05-20  0:00 ` Jon S Anthony
  2 siblings, 0 replies; 4+ messages in thread
From: Nick Roberts @ 1997-05-20  0:00 UTC (permalink / raw)





the AJE <whippet@light.iinet.net.au> wrote in article
<01bc6221$5c8b3100$1a8602cb@whippet>...
> I have only just begun learning ADA, but I can't find a book with decent
> examples on randomising numbers.  I could try using C++, but I much
prefer
> ADA.  The biggest problem is finding something to connect the randomizer
to
> the timer so that a different seed is used everytime the programme is
run. 
> I would appreciate some examples using dice-rolls etc. because I can't
> decipher syntaxes very well.


All standard implementations of Ada 95 must provide the packages
Ada.Numerics.Float_Random and Ada.Numerics.Discrete_Random, which provide
the facilities you require. In particular, calling the Reset procedure
without the Initiator parameter will seed the generator according to the
clock (in an implementation-defined manner).

A random (six-sided) dice-roll is easy to program using the Discrete_Random
package. First, declare a suitable subtype (or type):

   type Die_Face is range 1..6;

and then instantiate the package:

   package Dice_Random is new Ada.Numerics.Discrete_Random(Die_Face);
   use Dice_Random;

then declare a generator:

   type Die_Gen: Dice_Random.Generator;

and call Reset to seed by the clock:

   Reset(Die_Gen);

then you can call the Random function at any time to get a random 'dice
roll':

   DR: Die_Face;
   ...
   DR := Random(Die_Gen);

Hope this is of use.
Nick.





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

* Re: How do you randomise integers?
  1997-05-16  0:00 How do you randomise integers? the AJE
  1997-05-19  0:00 ` Michael F Brenner
  1997-05-20  0:00 ` Nick Roberts
@ 1997-05-20  0:00 ` Jon S Anthony
  2 siblings, 0 replies; 4+ messages in thread
From: Jon S Anthony @ 1997-05-20  0:00 UTC (permalink / raw)



In article <01bc6221$5c8b3100$1a8602cb@whippet> "the AJE" <whippet@light.iinet.net.au> writes:

> I have only just begun learning ADA, but I can't find a book with decent
> examples on randomising numbers.  I could try using C++, but I much prefer
> ADA.  The biggest problem is finding something to connect the randomizer to
> the timer so that a different seed is used everytime the programme is run. 
> I would appreciate some examples using dice-rolls etc. because I can't
> decipher syntaxes very well.

Is there some reason why you don't want/can't use the random number
generators that come with Ada (A.5.2).  The generic discrete version
seems like just what you want.  There is also an example Dice_Game
given as well.

/Jon

-- 
Jon Anthony
Organon Motives, Inc.
Belmont, MA 02178
617.484.3383
jsa@organon.com





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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-16  0:00 How do you randomise integers? the AJE
1997-05-19  0:00 ` Michael F Brenner
1997-05-20  0:00 ` Nick Roberts
1997-05-20  0:00 ` Jon S Anthony

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