[BACK]Return to ts_random.adb CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / PHC / Ada / Math_Lib / Numbers

Annotation of OpenXM_contrib/PHC/Ada/Math_Lib/Numbers/ts_random.adb, Revision 1.1.1.1

1.1       maekawa     1: with text_io,integer_io;                 use text_io,integer_io;
                      2: with Standard_Floating_Numbers;          use Standard_Floating_Numbers;
                      3: with Standard_Floating_Numbers_io;       use Standard_Floating_Numbers_io;
                      4: with Standard_Complex_Numbers;
                      5: with Standard_Complex_Numbers_io;        use Standard_Complex_Numbers_io;
                      6: with Standard_Random_Numbers;            use Standard_Random_Numbers;
                      7: with Multprec_Natural_Numbers;           use Multprec_Natural_Numbers;
                      8: with Multprec_Natural_Numbers_io;        use Multprec_Natural_Numbers_io;
                      9: with Multprec_Integer_Numbers;           use Multprec_Integer_Numbers;
                     10: with Multprec_Integer_Numbers_io;        use Multprec_Integer_Numbers_io;
                     11: with Multprec_Floating_Numbers;          use Multprec_Floating_Numbers;
                     12: with Multprec_Floating_Numbers_io;       use Multprec_Floating_Numbers_io;
                     13: with Multprec_Complex_Numbers;
                     14: with Multprec_Complex_Numbers_io;        use Multprec_Complex_Numbers_io;
                     15: with Multprec_Random_Numbers;            use Multprec_Random_Numbers;
                     16:
                     17: procedure ts_random is
                     18:
                     19:   procedure Random_Standard_Integer is
                     20:
                     21:     n : natural;
                     22:     low,upp,rndi : integer;
                     23:
                     24:   begin
                     25:     new_line;
                     26:     put_line("Testing the random generation of standard integer numbers.");
                     27:     new_line;
                     28:     put("Give lower bound : "); get(low);
                     29:     put("Give lower bound : "); get(upp);
                     30:     put("Give number of random integers : "); get(n);
                     31:     put_line("Generating random numbers : ");
                     32:     for i in 1..n loop
                     33:       rndi := Random(low,upp);
                     34:       put(rndi); new_line;
                     35:     end loop;
                     36:   end Random_Standard_Integer;
                     37:
                     38:   procedure Random_Standard_Complex is
                     39:
                     40:     n : natural;
                     41:     use Standard_Complex_Numbers;
                     42:     rndc : Complex_Number;
                     43:     absv : double_float;
                     44:
                     45:   begin
                     46:     new_line;
                     47:     put_line("Testing the random generation of standard complex numbers.");
                     48:     new_line;
                     49:     put("Give the number of randoms to be generated : "); get(n);
                     50:     for k in 1..n loop
                     51:       rndc := Random;
                     52:       put(" x = "); put(rndc);
                     53:       absv := AbsVal(rndc);
                     54:       put("   |x| = "); put(absv,3,3,3); new_line;
                     55:     end loop;
                     56:   end Random_Standard_Complex;
                     57:
                     58:   procedure Random_Multprec_Natural is
                     59:
                     60:     n,sz : natural;
                     61:     rnd : Natural_Number;
                     62:
                     63:   begin
                     64:     new_line;
                     65:     put_line("Testing the random generation of multi-precision naturals.");
                     66:     new_line;
                     67:     put("Give the size of the numbers : "); get(sz);
                     68:     put("Give number of random naturals : "); get(n);
                     69:     put_line("Generating random numbers : ");
                     70:     for i in 1..n loop
                     71:       rnd := Random(sz); put(rnd); new_line;
                     72:     end loop;
                     73:   end Random_Multprec_Natural;
                     74:
                     75:   procedure Random_Multprec_Integer is
                     76:
                     77:     n,sz : natural;
                     78:     rnd : Integer_Number;
                     79:
                     80:   begin
                     81:     new_line;
                     82:     put_line("Testing the random generation of multi-precision integers.");
                     83:     new_line;
                     84:     put("Give the size of the numbers : "); get(sz);
                     85:     put("Give number of random integers : "); get(n);
                     86:     put_line("Generating random numbers : ");
                     87:     for i in 1..n loop
                     88:       rnd := Random(sz); put(rnd); new_line;
                     89:     end loop;
                     90:   end Random_Multprec_Integer;
                     91:
                     92:   procedure Random_Multprec_Floating is
                     93:
                     94:     n,sz : natural;
                     95:     rnd : Floating_Number;
                     96:
                     97:   begin
                     98:     new_line;
                     99:     put_line("Testing the random generation of multi-precision floats.");
                    100:     new_line;
                    101:     put("Give the size of the numbers : "); get(sz);
                    102:     put("Give number of random floating numbers : "); get(n);
                    103:     put_line("Generating random numbers : ");
                    104:     for i in 1..n loop
                    105:       rnd := Random(sz); put(rnd); new_line;
                    106:     end loop;
                    107:   end Random_Multprec_Floating;
                    108:
                    109:   procedure Random_Multprec_Complex is
                    110:
                    111:     n,sz : natural;
                    112:     use Multprec_Complex_Numbers;
                    113:     rnd : Complex_Number;
                    114:
                    115:   begin
                    116:     new_line;
                    117:     put_line("Testing the random generation of multi-precision complex");
                    118:     new_line;
                    119:     put("Give the size of the numbers : "); get(sz);
                    120:     put("Give number of random complex numbers : "); get(n);
                    121:     put_line("Generating random numbers : ");
                    122:     for i in 1..n loop
                    123:       rnd := Random(sz); put(rnd); new_line;
                    124:     end loop;
                    125:   end Random_Multprec_Complex;
                    126:
                    127:   procedure Main is
                    128:
                    129:     ans : character;
                    130:
                    131:   begin
                    132:     new_line;
                    133:     put_line("Testing the Random Number Generators");
                    134:     loop
                    135:       new_line;
                    136:       put_line("Choose one of the following :");
                    137:       put_line("  0. exit the program.");
                    138:       put_line("  1. standard integer numbers.");
                    139:       put_line("  2. standard complex numbers.");
                    140:       put_line("  3. multi-precision natural numbers.");
                    141:       put_line("  4. multi-precision integer numbers.");
                    142:       put_line("  5. multi-precision floating numbers.");
                    143:       put_line("  6. multi-precision complex numbers.");
                    144:       put("Make your choice (0,1,2,3,4,5 or 6) : "); get(ans);
                    145:       exit when (ans = '0');
                    146:       case ans is
                    147:         when '1' => Random_Standard_Integer;
                    148:         when '2' => Random_Standard_Complex;
                    149:         when '3' => Random_Multprec_Natural;
                    150:         when '4' => Random_Multprec_Integer;
                    151:         when '5' => Random_Multprec_Floating;
                    152:         when '6' => Random_Multprec_Complex;
                    153:         when others => null;
                    154:       end case;
                    155:     end loop;
                    156:   end Main;
                    157:
                    158: begin
                    159:   Main;
                    160: end ts_random;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>