There is an example in section A.5.2 in the reference manual.
Jacob
--
There only exist 10 kinds of people: Those who know binary
numbers and those who don't know binary numbers.
An example of Gaussian distribution:
http://rosettacode.org/wiki/Random_numbers#Ada
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Hey tonyq,
I wrote this little tutorial a while ago:
http://wiki.ada-dk.org/index.php/The_Dice_Roller_Program
As the name suggests, the tutorial centers around a program that rolls
dice, and as such it needs to generate some random numbers. The part the
does the random stuff can be found here:
http://wiki.ada-dk.org/index.php/The_Dice_Roller_Program#dice-random.ads_and_dice-random.adb
It's not a very complicated routine, so you should be able to tweak it
to match your needs. :o)
--
Regards,
Thomas Lųcke
Email: tl at ada-dk.org
Web: http:ada-dk.org
IRC nick: ThomasLocke
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
which excludes the maximum value from the returned values.
--
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
> 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>
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.
> 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! :-)
Thanks for the help guys