help-octave
[Top][All Lists]

## RAND syntax

 From: John Eaton Subject: RAND syntax Date: Thu, 24 Aug 1995 00:08:20 -0500

```Eyal Doron <address@hidden> wrote:

:    I noticed that the syntax of "rand" seems to be out of date. It is the
: old syntax of Matlab 3.5, rather than the new syntax of Matlab 4.x,
: and indeed of the rest of Octave. Thus,
:
: octave:6> ones([2 2])
: ans =
:
:   1  1
:   1  1
:
: octave:7> rand([2,2])
: ans =
:
:   -1.83413  -0.83267
:
: (its on "normal"), so that "rand(size(A))" does not work as expected.
:
: I suggest this be fixed.

This will be fixed in the next release.  The patch follows.

Thanks,

jwe

*** src/f-rand.cc~      1995/06/25 19:56:32
--- src/f-rand.cc       1995/08/24 05:02:41
***************
*** 213,220 ****
--- 213,241 ----
}
else if (tmp.is_matrix_type ())
{
+ // XXX FIXME XXX -- this should probably use the function from data.cc.
+
+         Matrix a = args(0).matrix_value ();
+
+         if (error_state)
+           return retval;
+
n = a.rows ();
m = a.columns ();
+
+         if (n == 1 && m == 2)
+           {
+             n = NINT (a.elem (0, 0));
+             m = NINT (a.elem (0, 1));
+           }
+         else if (n == 2 && m == 1)
+           {
+             n = NINT (a.elem (0, 0));
+             m = NINT (a.elem (1, 0));
+           }
+         else
+           warning ("rand (A): use rand (size (A)) instead");
+
goto gen_matrix;
}
else

```