C.5 Declare Blocks - JulTob/Ada GitHub Wiki

Declare

There can be blocks of code with defined scope declared in the fly by the codeword declare

function random_integer(
  Min: in Integer;
  Max: in Integer)
  return Integer is
  -- This is the place for contract clouses for input
  ---- Reinforce Min <= Max
  begin 
     declare
       subtype Outputs is Integer range Min..Max;
       package Randint is new Ada.Numerics.Discrete_Random(
          Result_Subtype => Outputs);
       Dice: Randint.Generator;
       result: Outputs := Min;
       begin 
          Randint.Reset(Gen => Dice);
          Result := RandInt.Random(Gen => Dice);
          return Integer(Result);
       end;
  end random_integer;