Mercurial > hg > octave-nkf
comparison src/rand.cc @ 519:b9284136189a
[project @ 1994-07-19 14:40:20 by jwe]
author | jwe |
---|---|
date | Tue, 19 Jul 1994 14:42:19 +0000 |
parents | 309fc59f66ee |
children | 20fbad23ae51 |
comparison
equal
deleted
inserted
replaced
518:2349d5721cd9 | 519:b9284136189a |
---|---|
23 | 23 |
24 #ifdef HAVE_CONFIG_H | 24 #ifdef HAVE_CONFIG_H |
25 #include "config.h" | 25 #include "config.h" |
26 #endif | 26 #endif |
27 | 27 |
28 #include <time.h> | |
29 | |
28 #include "tree-const.h" | 30 #include "tree-const.h" |
29 #include "f77-uscore.h" | 31 #include "f77-uscore.h" |
30 #include "error.h" | 32 #include "error.h" |
31 #include "utils.h" | 33 #include "utils.h" |
32 #include "f-rand.h" | 34 #include "defun-dld.h" |
33 | 35 |
34 // Possible distributions of random numbers. | 36 // Possible distributions of random numbers. |
35 enum rand_dist { uniform, normal }; | 37 enum rand_dist { uniform, normal }; |
36 | 38 |
37 // Current distribution of random numbers. | 39 // Current distribution of random numbers. |
42 int *F77_FCN (dgennor) (double*, double*, double*); | 44 int *F77_FCN (dgennor) (double*, double*, double*); |
43 int *F77_FCN (dgenunf) (double*, double*, double*); | 45 int *F77_FCN (dgenunf) (double*, double*, double*); |
44 int *F77_FCN (setall) (int*, int*); | 46 int *F77_FCN (setall) (int*, int*); |
45 int *F77_FCN (getsd) (int*, int*); | 47 int *F77_FCN (getsd) (int*, int*); |
46 } | 48 } |
47 | |
48 #ifdef WITH_DLD | |
49 Octave_object | |
50 builtin_rand_2 (const Octave_object& args, int nargout) | |
51 { | |
52 return rand_internal (args, nargout); | |
53 } | |
54 #endif | |
55 | 49 |
56 static double | 50 static double |
57 curr_rand_seed (void) | 51 curr_rand_seed (void) |
58 { | 52 { |
59 union d2i { double d; int i[2]; }; | 53 union d2i { double d; int i[2]; }; |
96 else if (current_distribution == normal) | 90 else if (current_distribution == normal) |
97 return "normal"; | 91 return "normal"; |
98 else | 92 else |
99 { | 93 { |
100 panic_impossible (); | 94 panic_impossible (); |
101 return (char *) NULL; | 95 return 0; |
102 } | 96 } |
103 } | 97 } |
104 | 98 |
105 Octave_object | 99 DEFUN_DLD ("rand", Frand, Srand, 2, 1, |
106 rand_internal (const Octave_object& args, int nargout) | 100 "rand -- generate a random value\n\ |
107 { | 101 \n\ |
108 // Assumes that we have been given the correct number of arguments. | 102 rand (N) -- generate N x N matrix\n\ |
109 | 103 rand (A) -- generate matrix the size of A\n\ |
104 rand (N, M) -- generate N x M matrix\n\ | |
105 rand (\"dist\") -- get current distribution\n\ | |
106 rand (DISTRIBUTION) -- set distribution type (\"normal\" or \"uniform\"\n\ | |
107 rand (SEED) -- get current seed\n\ | |
108 rand (SEED, N) -- set seed") | |
109 { | |
110 Octave_object retval; | 110 Octave_object retval; |
111 | 111 |
112 int nargin = args.length (); | 112 int nargin = args.length (); |
113 | |
114 if (nargin > 3 || nargout > 1) | |
115 { | |
116 print_usage ("rand"); | |
117 return retval; | |
118 } | |
113 | 119 |
114 static int initialized = 0; | 120 static int initialized = 0; |
115 if (! initialized) | 121 if (! initialized) |
116 { | 122 { |
117 // Make the random number generator give us a different sequence every | 123 // Make the random number generator give us a different sequence every |