comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Generating a random number, not sure why I'm getting this error
Date: Sun, 15 Nov 2015 19:29:02 -0700
Date: 2015-11-15T19:29:02-07:00	[thread overview]
Message-ID: <n2bet4$595$1@dont-email.me> (raw)
In-Reply-To: <c1e10951-7548-46a9-9df2-6f3a531a6bf2@googlegroups.com>

On 11/15/2015 06:25 PM, John Smith wrote:
> 
> with Ada.Numerics.Discrete_Random; ... 
> Ada.Numerics.Discrete_Random.Reset(Ada.Numerics.Discrete_Random.Generator);

Generator is a type, not something you can pass to a subprogram. What would you
expect a call to Random to return?

> And this is the error that I get:
> 
> :13:15: invalid prefix in selected component "Ada.Numerics.Discrete_Random"
> -- refers to the first Ada.Numerics.Discrete_Random...

Not a great error msg.

Discrete_Random is not a package: it's a generic package. You can consider a
generic like a template for a package or subprogram. You create a package or
subprogram from the generic through what Ada calls instantiation. When you
instantiate Discrete_Random, you supply a discrete subtype to fill in for
Result_Subtype; Random returns a value of this subtype.

So, for example,

package Random is new Ada.Numerics.Discrete_Random (Result_Subtype => Character;
-- Random is the name of the pkg created by the instantiation

Gen : Random.Generator;
C   : Character;

Random.Reset (Gen => Gen);
C := Random.Random (Gen);

-- 
Jeff Carter
"Apart from the sanitation, the medicine, education, wine,
public order, irrigation, roads, the fresh water system,
and public health, what have the Romans ever done for us?"
Monty Python's Life of Brian
80

  reply	other threads:[~2015-11-16  2:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16  1:25 Generating a random number, not sure why I'm getting this error John Smith
2015-11-16  2:29 ` Jeffrey R. Carter [this message]
2015-11-16  2:53   ` John Smith
2015-11-16  8:51     ` Simon Wright
replies disabled

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