ball_game/src/random_functions.adb

39 lines
1.3 KiB
Ada

package body Random_Functions is
function Spawn_Enemy return Boolean is
subtype Die is Natural range 1 .. 6;
subtype Dice is Natural range 2 * Die'First .. 2 * Die'Last;
package Random_Die is new Ada.Numerics.Discrete_Random (Die);
use Random_Die;
G : Generator;
D : Dice;
Random_Number : Natural;
begin
Reset (G);
Random_Number := Random (G);
if Random_Number = 2 then
return True;
else
return False;
end if;
end Spawn_Enemy;
function Generate_Coordinates (Limit : Float) return Float is
subtype Coordinate is Integer range 1 .. Integer (Limit);
subtype Coordinates is
Integer range 2 * Coordinate'First .. 2 * Coordinate'Last;
package Random_Coordinate is new Ada.Numerics.Discrete_Random
(Coordinate);
use Random_Coordinate;
G : Generator;
D : Coordinates;
Random_Number : Float;
begin
Reset (G);
Random_Number := Float (Random (G));
if Random_Number < 0.0 then
Random_Number := Random_Number * (-1.0);
end if;
return Random_Number;
end Generate_Coordinates;
end Random_Functions;