home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog4 / testran.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  1.9 KB  |  74 lines

  1.                                    -- Chapter 31 - Program 2
  2. with Text_IO, Random;
  3. use Text_IO;
  4.  
  5. procedure TestRan is
  6.  
  7.    package My_Random is new Random(FLOAT);
  8.    use My_Random;
  9.  
  10.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  11.    use Int_IO;
  12.    package Flt_IO is new Text_IO.Float_IO(FLOAT);
  13.    use Flt_IO;
  14.  
  15.    SIZE : constant := 100;
  16.    type MY_ARRAY is array(1..SIZE) of INTEGER;
  17.    Events   : MY_ARRAY;
  18.    Int_Rand : INTEGER;
  19.  
  20. begin
  21.    Set_Seed;
  22.    Put("The starting value of the seed is ");
  23.    Put(Get_Seed,3,6,0);
  24.    New_Line;
  25.    for Index in 1..12 loop
  26.       Put("The random number is ");
  27.       Put(Random_Number,3,6,0);
  28.       New_Line;
  29.    end loop;
  30.  
  31.    for Index in 1..SIZE loop
  32.       Events(Index) := 0;
  33.    end loop;
  34.  
  35.    for Index in 1..10000 loop
  36.       Int_Rand := INTEGER(0.5 + (FLOAT(SIZE) * Random_Number));
  37.       Events(Int_Rand) := Events(Int_Rand) + 1;
  38.    end loop;
  39.    New_Line(2);
  40.  
  41.    for Index in 1..Size loop
  42.       Put(Events(Index),4);
  43.    end loop;
  44. end TestRan;
  45.  
  46.  
  47.  
  48.  
  49. -- Result of execution
  50.  
  51. -- The starting value of the seed is   0.195333
  52. -- The random number is   0.786685
  53. -- The random number is   0.926148
  54. -- The random number is   0.902392
  55. -- The random number is   0.736096
  56. -- The random number is   0.572030
  57. -- The random number is   0.423565
  58. -- The random number is   0.384310
  59. -- The random number is   0.109521
  60. -- The random number is   0.186004
  61. -- The random number is   0.721385
  62. -- The random number is   0.469050
  63. -- The random number is   0.702704
  64.  
  65. --  109  97 102  96 107  98  85  87 104 111 113 115 108  99 112 ...
  66. --   97  93 107  91 101  85  91 103  95 101 102  98  95 118 110 ...
  67. --   87 106 103 102  93 129 112  94 102  89  95 104  98  94  98 ...
  68. --   93 106  96 104 119  95  82  97 112  82 104 103  97 107 112 ...
  69. --   93  96 101  98 109  95  94  99  80  74  99  85  76 117 124 ...
  70.  
  71. -- (Note; only fifteen are listed in each row to stay within
  72. --        70 columns.)
  73.  
  74.