From: John B. Matthews on
In article <i1i3cc$8ro$1(a)tornado.tornevall.net>,
"Jeffrey R. Carter" <spam.jrcarter.not(a)spam.acm.org> wrote:

> On 07/13/2010 05:45 AM, tonyg wrote:
> > I want to generate a random integer and a random floating point
> > number between 10 and 30 . I've been looking at previous posts and
> > finding it a little confusing with many packages, has anyone an
> > already done example in ada 2005 they can post up?

Here's an Ada 95 example that uses Ada.Numerics.Discrete_Random to
simulate repeated plays of a simple card game:

<http://home.roadrunner.com/~jbmatthews/war.html>

The shuffling algorithm needs work; this might be an alternative:

<http://en.wikipedia.org/wiki/Fisher–Yates_shuffle>

> The random integer is pretty easy to do with an appropriate [sub]type
> and Ada.Numerics.Discrete_Random. The random floating-point is a bit
> more difficult, and there's always the question of whether 30.0 must
> be a possible value. You can have a look at Random_Range in
> PragmARC.Universal_Random:
>
> http://pragmada.x10hosting.com/pragmarc.htm

As an aside, Mine Detector V6.0 builds on Mac OS X 10.5.8 with GtkAda
2.14.1 and GNAT 4.3.4. Wait, I took a picture:

<http://i26.tinypic.com/23qyxxi.png>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: Jeffrey R. Carter on
On 07/13/2010 01:33 PM, John B. Matthews wrote:
>
> The shuffling algorithm needs work; this might be an alternative:
>
> <http://en.wikipedia.org/wiki/Fisher–Yates_shuffle>

The problem with this (for Ada) is the need to instantiate Discrete_Random for a
different range each time (although you could use
PragmARC.Universal_Random.Random_Int). If it's for a game with a human, then the
biased version of using the full range each time is good enough

> As an aside, Mine Detector V6.0 builds on Mac OS X 10.5.8 with GtkAda
> 2.14.1 and GNAT 4.3.4. Wait, I took a picture:
>
> <http://i26.tinypic.com/23qyxxi.png>

Cool. I wouldn't check any boxes with only 100 mines.

--
Jeff Carter
"When Roman engineers built a bridge, they had to stand under it
while the first legion marched across. If programmers today
worked under similar ground rules, they might well find
themselves getting much more interested in Ada!"
Robert Dewar
62
From: John B. Matthews on
In article <i1irmb$vfe$1(a)tornado.tornevall.net>,
"Jeffrey R. Carter" <spam.jrcarter.not(a)spam.acm.org> wrote:

> On 07/13/2010 01:33 PM, John B. Matthews wrote:
> >
> > The shuffling algorithm needs work; this might be an alternative:
> >
> > <http://en.wikipedia.org/wiki/Fisher–Yates_shuffle>
>
> The problem with this (for Ada) is the need to instantiate
> Discrete_Random for a different range each time (although you could
> use PragmARC.Universal_Random.Random_Int).

Thank you for suggesting this; I see the problem, now. Section
A.5.2(50), Note 16, mentions the very problem, suggesting Float_Random
as an alternative:

<http://www.adaic.com/standards/05rm/html/RM-A-5-2.html>

I also found this implementation using Discrete_Random:

<http://rosettacode.org/wiki/Knuth_shuffle#Ada>

> If it's for a game with a human, then the biased version of using the
> full range each time is good enough.

No, it's a simulation; I don't get off that easy.

> > As an aside, Mine Detector V6.0 builds on Mac OS X 10.5.8 with GtkAda
> > 2.14.1 and GNAT 4.3.4. Wait, I took a picture:
> >
> > <http://i26.tinypic.com/23qyxxi.png>
>
> Cool. I wouldn't check any boxes with only 100 mines.

They were smiling for the camera! :-)

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: tonyg on
On 14 July, 05:42, "John B. Matthews" <nos...(a)nospam.invalid> wrote:
> In article <i1irmb$vf...(a)tornado.tornevall.net>,
>  "Jeffrey R. Carter" <spam.jrcarter....(a)spam.acm.org> wrote:
>
> > On 07/13/2010 01:33 PM, John B. Matthews wrote:
>
> > > The shuffling algorithm needs work; this might be an alternative:
>
> > > <http://en.wikipedia.org/wiki/Fisher–Yates_shuffle>
>
> > The problem with this (for Ada) is the need to instantiate
> > Discrete_Random for a different range each time (although you could
> > use PragmARC.Universal_Random.Random_Int).
>
> Thank you for suggesting this; I see the problem, now. Section
> A.5.2(50), Note 16, mentions the very problem, suggesting Float_Random
> as an alternative:
>
> <http://www.adaic.com/standards/05rm/html/RM-A-5-2.html>
>
> I also found this implementation using Discrete_Random:
>
> <http://rosettacode.org/wiki/Knuth_shuffle#Ada>
>
> > If it's for a game with a human, then the biased version of using the
> > full range each time is good enough.
>
> No, it's a simulation; I don't get off that easy.
>
> > > As an aside, Mine Detector V6.0 builds on Mac OS X 10.5.8 with GtkAda
> > > 2.14.1 and GNAT 4.3.4. Wait, I took a picture:
>
> > > <http://i26.tinypic.com/23qyxxi.png>
>
> > Cool. I wouldn't check any boxes with only 100 mines.
>
> They were smiling for the camera! :-)
>
> --
> John B. Matthews
> trashgod at gmail dot com
> <http://sites.google.com/site/drjohnbmatthews>

Thanks for the help guys