From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Generating a random number, not sure why I'm getting this error Date: Sun, 15 Nov 2015 19:29:02 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Mon, 16 Nov 2015 02:26:46 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="caa759af2a9c666aec02942f6fe5abd6"; logging-data="5413"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+VydR1j07J/bWQPpk9UYxAoNlxvtHmhMo=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: Cancel-Lock: sha1:T8iXZrViG7GdeY6cawXopnzGNQ4= X-Enigmail-Draft-Status: N1110 Xref: news.eternal-september.org comp.lang.ada:28384 Date: 2015-11-15T19:29:02-07:00 List-Id: 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