with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Numerics.Float_Random;
with Ada.Numerics.Discrete_Random;
procedure Probability is
subtype My_Characters is
Character range 'a' .. 'z';
package My_Random_Character_Package is
new Ada.Numerics.Discrete_Random(My_Characters);
use My_Random_Character_Package;
Gen_1 : My_Random_Character_Package.Generator;
procedure My_Character_Program(First_Character, Second_Character : in Character) is
begin
Put(First_Character);
Put(" ");
Put(Second_Character);
New_Line;
Put("All characters between ");
Put(First_Character);
Put(" and ");
Put(Second_Character);
Put(":");
for C in Character range First_Character .. Second_Character loop
Put(" ");
Put(A);
end loop;
end My_Character_Program;
procedure Part_2 is
First_Character, Second_Character : Character;
begin
Put_Line("PART 2:");
Put_Line("Two random characters from a to z will now be generated.");
Put("Random characters: ");
First_Character := Random(Gen_1);
Second_Character := Random(Gen_1);
if First_Character > Second_Character then
My_Character_Program(Second_Character, First_Character);
else
My_Character_Program(First_Character, Second_Character);
end if;
end Part_2;
begin
-- Reset(Gen_1);
Part_2;
New_Line(2);
end Probability;
The following program will pick two random letters between A and Z and then it will type out all the letters thats between them. So for instance if it randomly generates the letters
d and g
it will type out
d e f g
But I need your asstistance. Even if my program works I don't think its executed that well, especially the part 2. Is there not a way where I can put a part of my "Part 2 procedure" in my "My character program procedure"? As you can see I swaped the first and second character. Can I not do that in another way?
I appreciate any help that I could get.