fork download
  1. with Ada.Text_IO, Random;
  2. use Ada.Text_IO;
  3.  
  4. procedure Set_Seed is
  5. Time_And_Date : TIME;
  6. All_Day : DAY_DURATION;
  7. Minutes : FLOAT_ITEM;
  8. Int_Minutes : INTEGER;
  9. Part_Of_A_Minute : FLOAT_ITEM;
  10. begin
  11. Time_And_Date := Clock; -- Get the time and date
  12. All_Day := Seconds(Time_And_Date); -- Seconds since midnight
  13. Minutes := FLOAT_ITEM(All_Day) / 60.0; -- Floating type Minutes
  14. Int_Minutes := INTEGER(Minutes - 0.5); -- Integer type minutes
  15. Part_Of_A_Minute := FLOAT_ITEM(All_Day)
  16. - 60.0 * FLOAT_ITEM(Int_Minutes);
  17. X_Initial := 0.1;
  18. end Set_Seed;
  19.  
  20.  
  21. procedure Force_Seed(Start_Seed : FLOAT_ITEM) is
  22. Temp : FLOAT_ITEM;
  23. Natural_Temp : NATURAL;
  24. begin
  25. Natural_Temp := NATURAL(Start_Seed - 0.5);
  26. Temp := Start_Seed - FLOAT_ITEM(Natural_Temp);
  27. X_Initial := Start_Seed;
  28. exception
  29. when Constraint_Error =>
  30. Put_Line("Seed out of range, ignored");
  31. end Force_Seed;
  32.  
  33.  
  34. function Get_Seed return FLOAT_ITEM is
  35. begin
  36. return X_Initial;
  37. end Get_Seed;
  38.  
  39.  
  40. function Random_Number return FLOAT_ITEM is
  41. Temp : FLOAT_ITEM;
  42. Natural_Temp : NATURAL;
  43. begin
  44. Temp := A * X_Initial + C;
  45. Natural_Temp := NATURAL(Temp - 0.5);
  46. Temp := Temp - FLOAT_ITEM(Natural_Temp);
  47. X_Initial := Temp;
  48. return Temp;
  49. end Random_Number;
  50.  
  51. procedure TestRan is
  52.  
  53. package My_Random is new Random(FLOAT);
  54. use My_Random;
  55.  
  56. package Int_IO is new Ada.Text_IO.Integer_IO(INTEGER);
  57. use Int_IO;
  58. package Flt_IO is new Ada.Text_IO.Float_IO(FLOAT);
  59. use Flt_IO;
  60.  
  61. SIZE : constant := 100;
  62. type MY_ARRAY is array(1..SIZE) of INTEGER;
  63. Events : MY_ARRAY;
  64. Int_Rand : INTEGER;
  65.  
  66. begin
  67. Set_Seed;
  68. for Index in 1..2 loop
  69. Put(Random_Number, 2, 6, 0);
  70. end loop;
  71.  
  72. end TestRan;
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
gnatgcc -c -pipe -O2 prog.adb
prog.adb:21:01: end of file expected, file can have only one compilation unit
gnatmake: "prog.adb" compilation error
stdout
Standard output is empty