1

I'm trying to generate a random Positive in ada in my procedure. For this, I have the following code:

  procedure Inicialize(K: Positive) is
     package rand is new ada.numerics.discrete_random(Positive);
     use rand;
     G: Generator;
     t: Positive;
  begin         
     isInitialized:= True;
     reset(G); 
     t := random(G); --error for this line
  end Inicialize;

I get the error

incorrect use of "random"

I have no idea, how is this an incorrect use, or what does it even mean. Could someone please elaborate? Thank you!

lte__
  • 7,175
  • 25
  • 74
  • 131

1 Answers1

3

Assuming isInitialized is a global variable, that code looks legal as it stands. It compiles and runs correctly with a current Gnat Ada. Is the full procedure more complicated than this? Could G or random be being redeclared?

I see your earlier question which mentions a package random. So it's likely a name clash between the package name and the procedure name. Removing the 'use rand', or renaming the package, would cure this.

Community
  • 1
  • 1
  • 1
    I see an earlier question which mentions a package 'random'. So it's likely a name clash between the package name and the procedure name. Removing the 'use rand', or renaming the package, would cure this. – Graham Stark May 07 '16 at 14:29