GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
rand.cc
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////*
2 //
3 // Copyright (C) 1996-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <ctime>
31 #include <unordered_map>
32 #include <string>
33 
34 #include "f77-fcn.h"
35 #include "lo-mappers.h"
36 #include "oct-rand.h"
37 #include "quit.h"
38 
39 #include "defun.h"
40 #include "error.h"
41 #include "errwarn.h"
42 #include "ovl.h"
43 #include "unwind-prot.h"
44 #include "utils.h"
45 #include "ov-re-mat.h"
46 
47 /*
48 %% Restore all rand* "seed" and "state" values in order, so that the
49 %% new "state" algorithm remains active after these tests complete.
50 %!function restore_rand_states (seed, state)
51 %! rand ("seed", seed.rand);
52 %! rande ("seed", seed.rande);
53 %! randg ("seed", seed.randg);
54 %! randn ("seed", seed.randn);
55 %! randp ("seed", seed.randp);
56 %! rand ("state", state.rand);
57 %! rande ("state", state.rande);
58 %! randg ("state", state.randg);
59 %! randn ("state", state.randn);
60 %! randp ("state", state.randp);
61 %!endfunction
62 
63 %!shared __random_statistical_tests__, old_seed, old_state, restore_state
64 %! ## Flag whether the statistical tests should be run in "make check" or not
65 %! __random_statistical_tests__ = 0;
66 %! ## Save and restore the states of each of the random number generators
67 %! ## that are tested by the unit tests in this file.
68 %! old_seed.rand = rand ("seed");
69 %! old_seed.rande = rande ("seed");
70 %! old_seed.randg = randg ("seed");
71 %! old_seed.randn = randn ("seed");
72 %! old_seed.randp = randp ("seed");
73 %! old_state.rand = rand ("state");
74 %! old_state.rande = rande ("state");
75 %! old_state.randg = randg ("state");
76 %! old_state.randn = randn ("state");
77 %! old_state.randp = randp ("state");
78 %! restore_state = onCleanup (@() restore_rand_states (old_seed, old_state));
79 */
80 
81 static octave_value
82 do_rand (const octave_value_list& args, int nargin, const char *fcn,
83  const std::string& distribution, bool additional_arg = false)
84 {
85  NDArray a;
86  int idx = 0;
87  bool is_single = false;
88 
89  if (nargin > 0 && args(nargin-1).is_string ())
90  {
91  std::string s_arg = args(nargin-1).string_value ();
92 
93  if (s_arg == "single")
94  {
95  is_single = true;
96  nargin--;
97  }
98  else if (s_arg == "double")
99  nargin--;
100  }
101 
102  if (additional_arg)
103  {
104  if (nargin == 0)
105  error ("%s: at least one argument is required", fcn);
106  else if (args(0).is_string ())
107  additional_arg = false;
108  else
109  {
110  a = args(0).xarray_value ("%s: dimension must be a scalar integer", fcn);
111 
112  idx++;
113  nargin--;
114  }
115  }
116 
118  dim_vector dims;
119 
121  // Restore current distribution on any exit.
124 
125  octave::rand::distribution (distribution);
126 
127  switch (nargin)
128  {
129  case 0:
130  {
131  if (additional_arg)
132  dims = a.dims ();
133  else
134  {
135  dims.resize (2);
136 
137  dims(0) = 1;
138  dims(1) = 1;
139  }
140 
141  goto gen_matrix;
142  }
143  break;
144 
145  case 1:
146  {
147  octave_value tmp = args(idx);
148 
149  if (tmp.is_string ())
150  {
151  std::string s_arg = tmp.string_value ();
152 
153  if (s_arg == "dist")
155  else if (s_arg == "seed")
157  else if (s_arg == "state" || s_arg == "twister")
158  retval = octave::rand::state (fcn);
159  else if (s_arg == "uniform")
161  else if (s_arg == "normal")
163  else if (s_arg == "exponential")
165  else if (s_arg == "poisson")
167  else if (s_arg == "gamma")
169  else
170  error ("%s: unrecognized string argument", fcn);
171  }
172  else if (tmp.is_scalar_type ())
173  {
174  octave_idx_type n = tmp.idx_type_value (true);
175 
176  dims.resize (2);
177 
178  dims(0) = dims(1) = n;
179 
180  goto gen_matrix;
181  }
182  else if (tmp.is_range ())
183  {
184  Range r = tmp.range_value ();
185 
186  if (! r.all_elements_are_ints ())
187  error ("%s: all elements of range must be integers", fcn);
188 
189  octave_idx_type n = r.numel ();
190 
191  dims.resize (n);
192 
193  octave_idx_type base = octave::math::nint_big (r.base ());
194  octave_idx_type incr = octave::math::nint_big (r.inc ());
195 
196  for (octave_idx_type i = 0; i < n; i++)
197  {
198  // Negative dimensions treated as zero for Matlab compatibility
199  dims(i) = (base >= 0 ? base : 0);
200  base += incr;
201  }
202 
203  goto gen_matrix;
204  }
205  else if (tmp.is_matrix_type ())
206  {
208 
209  try
210  {
211  iv = tmp.octave_idx_type_vector_value (true);
212  }
213  catch (octave::execution_exception& e)
214  {
215  error (e, "%s: dimensions must be a scalar or array of integers", fcn);
216  }
217 
218  octave_idx_type len = iv.numel ();
219 
220  dims.resize (len);
221 
222  for (octave_idx_type i = 0; i < len; i++)
223  {
224  // Negative dimensions treated as zero for Matlab compatibility
225  octave_idx_type elt = iv(i);
226  dims(i) = (elt >=0 ? elt : 0);
227  }
228 
229  goto gen_matrix;
230  }
231  else
232  err_wrong_type_arg ("rand", tmp);
233  }
234  break;
235 
236  default:
237  {
238  octave_value tmp = args(idx);
239 
240  if (nargin == 2 && tmp.is_string ())
241  {
242  std::string ts = tmp.string_value ();
243 
244  if (ts == "seed")
245  {
246  if (args(idx+1).is_real_scalar ())
247  {
248  double d = args(idx+1).double_value ();
249 
251  }
252  else if (args(idx+1).is_string ()
253  && args(idx+1).string_value () == "reset")
255  else
256  error ("%s: seed must be a real scalar", fcn);
257  }
258  else if (ts == "state" || ts == "twister")
259  {
260  if (args(idx+1).is_string ()
261  && args(idx+1).string_value () == "reset")
262  octave::rand::reset (fcn);
263  else
264  {
265  ColumnVector s
266  = ColumnVector (args(idx+1).vector_value (false, true));
267 
268  // Backwards compatibility with previous versions of
269  // Octave which mapped Inf to 0.
270  for (octave_idx_type i = 0; i < s.numel (); i++)
271  if (octave::math::isinf (s.xelem (i)))
272  s.xelem (i) = 0.0;
273 
274  octave::rand::state (s, fcn);
275  }
276  }
277  else
278  error ("%s: unrecognized string argument", fcn);
279  }
280  else
281  {
282  dims.resize (nargin);
283 
284  for (int i = 0; i < nargin; i++)
285  {
286  octave_idx_type elt = args(idx+i).idx_type_value (true);
287 
288  // Negative dimensions treated as zero for Matlab compatibility
289  dims(i) = (elt >= 0 ? elt : 0);
290  }
291 
292  goto gen_matrix;
293  }
294  }
295  break;
296  }
297 
298  // No "goto gen_matrix" in code path. Must be done processing.
299  return retval;
300 
301 gen_matrix:
302 
303  dims.chop_trailing_singletons ();
304 
305  if (is_single)
306  {
307  if (additional_arg)
308  {
309  if (a.numel () == 1)
310  return octave::rand::float_nd_array (dims, a(0));
311  else
312  {
313  if (a.dims () != dims)
314  error ("%s: mismatch in argument size", fcn);
315 
316  octave_idx_type len = a.numel ();
317  FloatNDArray m (dims);
318  float *v = m.fortran_vec ();
319 
320  for (octave_idx_type i = 0; i < len; i++)
321  v[i] = octave::rand::float_scalar (a(i));
322 
323  return m;
324  }
325  }
326  else
327  return octave::rand::float_nd_array (dims);
328  }
329  else
330  {
331  if (additional_arg)
332  {
333  if (a.numel () == 1)
334  return octave::rand::nd_array (dims, a(0));
335  else
336  {
337  if (a.dims () != dims)
338  error ("%s: mismatch in argument size", fcn);
339 
340  octave_idx_type len = a.numel ();
341  NDArray m (dims);
342  double *v = m.fortran_vec ();
343 
344  for (octave_idx_type i = 0; i < len; i++)
345  v[i] = octave::rand::scalar (a(i));
346 
347  return m;
348  }
349  }
350  else
351  return octave::rand::nd_array (dims);
352  }
353 }
354 
355 DEFUN (rand, args, ,
356  doc: /* -*- texinfo -*-
357 @deftypefn {} {} rand (@var{n})
358 @deftypefnx {} {} rand (@var{m}, @var{n}, @dots{})
359 @deftypefnx {} {} rand ([@var{m} @var{n} @dots{}])
360 @deftypefnx {} {@var{v} =} rand ("state")
361 @deftypefnx {} {} rand ("state", @var{v})
362 @deftypefnx {} {} rand ("state", "reset")
363 @deftypefnx {} {@var{v} =} rand ("seed")
364 @deftypefnx {} {} rand ("seed", @var{v})
365 @deftypefnx {} {} rand ("seed", "reset")
366 @deftypefnx {} {} rand (@dots{}, "single")
367 @deftypefnx {} {} rand (@dots{}, "double")
368 Return a matrix with random elements uniformly distributed on the
369 interval (0, 1).
370 
371 The arguments are handled the same as the arguments for @code{eye}.
372 
373 You can query the state of the random number generator using the form
374 
375 @example
376 v = rand ("state")
377 @end example
378 
379 This returns a column vector @var{v} of length 625. Later, you can restore
380 the random number generator to the state @var{v} using the form
381 
382 @example
383 rand ("state", v)
384 @end example
385 
386 @noindent
387 You may also initialize the state vector from an arbitrary vector of length
388 @leq{} 625 for @var{v}. This new state will be a hash based on the value of
389 @var{v}, not @var{v} itself.
390 
391 By default, the generator is initialized from @code{/dev/urandom} if it is
392 available, otherwise from CPU time, wall clock time, and the current
393 fraction of a second. Note that this differs from @sc{matlab}, which
394 always initializes the state to the same state at startup. To obtain
395 behavior comparable to @sc{matlab}, initialize with a deterministic state
396 vector in Octave's startup files (@pxref{Startup Files}).
397 
398 To compute the pseudo-random sequence, @code{rand} uses the Mersenne
399 Twister with a period of @math{2^{19937}-1}
400 (See @nospell{M. Matsumoto and T. Nishimura},
401 @cite{Mersenne Twister: A 623-dimensionally equidistributed uniform
402 pseudorandom number generator},
403 @nospell{ACM} Trans.@: on Modeling and Computer Simulation Vol.@: 8, No.@: 1,
404 pp.@: 3--30, January 1998,
405 @url{http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html}).
406 Do @strong{not} use for cryptography without securely hashing several
407 returned values together, otherwise the generator state can be learned after
408 reading 624 consecutive values.
409 
410 Older versions of Octave used a different random number generator.
411 The new generator is used by default as it is significantly faster than the
412 old generator, and produces random numbers with a significantly longer cycle
413 time. However, in some circumstances it might be desirable to obtain the
414 same random sequences as produced by the old generators. To do this the
415 keyword @qcode{"seed"} is used to specify that the old generators should
416 be used, as in
417 
418 @example
419 rand ("seed", val)
420 @end example
421 
422 @noindent
423 which sets the seed of the generator to @var{val}. The seed of the
424 generator can be queried with
425 
426 @example
427 s = rand ("seed")
428 @end example
429 
430 However, it should be noted that querying the seed will not cause
431 @code{rand} to use the old generators, only setting the seed will. To cause
432 @code{rand} to once again use the new generators, the keyword
433 @qcode{"state"} should be used to reset the state of the @code{rand}.
434 
435 The state or seed of the generator can be reset to a new random value using
436 the @qcode{"reset"} keyword.
437 
438 The class of the value returned can be controlled by a trailing
439 @qcode{"double"} or @qcode{"single"} argument. These are the only valid
440 classes.
441 @seealso{randn, rande, randg, randp}
442 @end deftypefn */)
443 {
444  return do_rand (args, args.length (), "rand", "uniform");
445 }
446 
447 // FIXME: The old generator (selected when "seed" is set) will not
448 // work properly if compiled to use 64-bit integers.
449 
450 /*
451 %!test # "state" can be a scalar
452 %! rand ("state", 12); x = rand (1,4);
453 %! rand ("state", 12); y = rand (1,4);
454 %! assert (x, y);
455 %!test # "state" can be a vector
456 %! rand ("state", [12,13]); x = rand (1,4);
457 %! rand ("state", [12;13]); y = rand (1,4);
458 %! assert (x, y);
459 %!test # querying "state" returns a value which can be used later
460 %! s = rand ("state"); x = rand (1,2);
461 %! rand ("state", s); y = rand (1,2);
462 %! assert (x, y);
463 %!test # querying "state" doesn't disturb sequence
464 %! rand ("state", 12); rand (1,2); x = rand (1,2);
465 %! rand ("state", 12); rand (1,2); s = rand ("state"); y = rand (1,2);
466 %! assert (x, y);
467 %! rand ("state", s); z = rand (1,2);
468 %! assert (x, z);
469 %!test # "seed" must be a scalar
470 %! rand ("seed", 12); x = rand (1,4);
471 %! rand ("seed", 12); y = rand (1,4);
472 %! assert (x, y);
473 %!error <seed must be a real scalar> rand ("seed", [12,13])
474 %!test # querying "seed" returns a value which can be used later
475 %! s = rand ("seed"); x = rand (1,2);
476 %! rand ("seed", s); y = rand (1,2);
477 %! assert (x, y);
478 %!test # querying "seed" doesn't disturb sequence
479 %! rand ("seed", 12); rand (1,2); x = rand (1,2);
480 %! rand ("seed", 12); rand (1,2); s = rand ("seed"); y = rand (1,2);
481 %! assert (x, y);
482 %! rand ("seed", s); z = rand (1,2);
483 %! assert (x, z);
484 */
485 
486 /*
487 %!test
488 %! ## Test a known fixed state
489 %! rand ("state", 1);
490 %! assert (rand (1,6), [0.1343642441124013 0.8474337369372327 0.763774618976614 0.2550690257394218 0.495435087091941 0.4494910647887382], eps);
491 %!test
492 %! ## Test a known fixed seed
493 %! rand ("seed", 1);
494 %! assert (rand (1,6), [0.8668024251237512 0.9126510815694928 0.09366085007786751 0.1664607301354408 0.7408077004365623 0.7615650338120759], 1e-6);
495 %!test
496 %! if (__random_statistical_tests__)
497 %! ## statistical tests may fail occasionally.
498 %! rand ("state", 12);
499 %! x = rand (100_000, 1);
500 %! assert (min (x) > 0); #*** Please report this!!! ***
501 %! assert (max (x) < 1); #*** Please report this!!! ***
502 %! assert (mean (x), 0.5, 0.0024);
503 %! assert (var (x), 1/48, 0.0632);
504 %! assert (skewness (x), 0, 0.012);
505 %! assert (kurtosis (x), -6/5, 0.0094);
506 %! endif
507 %!test
508 %! if (__random_statistical_tests__)
509 %! ## statistical tests may fail occasionally.
510 %! rand ("seed", 12);
511 %! x = rand (100_000, 1);
512 %! assert (max (x) < 1); #*** Please report this!!! ***
513 %! assert (min (x) > 0); #*** Please report this!!! ***
514 %! assert (mean (x), 0.5, 0.0024);
515 %! assert (var (x), 1/48, 0.0632);
516 %! assert (skewness (x), 0, 0.012);
517 %! assert (kurtosis (x), -6/5, 0.0094);
518 %! endif
519 */
520 
521 /*
522 ## Test out-of-range values as rand() seeds.
523 %!function v = __rand_sample__ (initval)
524 %! rand ("state", initval);
525 %! v = rand (1, 6);
526 %!endfunction
527 %!
528 %!assert (__rand_sample__ (-1), __rand_sample__ (0))
529 %!assert (__rand_sample__ (-Inf), __rand_sample__ (0))
530 %!assert (__rand_sample__ (2^33), __rand_sample__ (intmax ("uint32")))
531 %!assert (__rand_sample__ (Inf), __rand_sample__ (0))
532 %!assert (__rand_sample__ (NaN), __rand_sample__ (0))
533 */
534 
535 /*
536 ## Check that negative dimensions are treated as zero for Matlab compatibility
537 %!assert (size (rand (1, -1, 2)), [1, 0, 2])
538 
539 ## Test input validation
540 %!error <conversion of 1.1 to.* failed> rand (1, 1.1)
541 %!error <dimensions must be .* array of integers> rand ([1, 1.1])
542 */
543 
545 
546 DEFUN (randn, args, ,
547  doc: /* -*- texinfo -*-
548 @deftypefn {} {} randn (@var{n})
549 @deftypefnx {} {} randn (@var{m}, @var{n}, @dots{})
550 @deftypefnx {} {} randn ([@var{m} @var{n} @dots{}])
551 @deftypefnx {} {@var{v} =} randn ("state")
552 @deftypefnx {} {} randn ("state", @var{v})
553 @deftypefnx {} {} randn ("state", "reset")
554 @deftypefnx {} {@var{v} =} randn ("seed")
555 @deftypefnx {} {} randn ("seed", @var{v})
556 @deftypefnx {} {} randn ("seed", "reset")
557 @deftypefnx {} {} randn (@dots{}, "single")
558 @deftypefnx {} {} randn (@dots{}, "double")
559 Return a matrix with normally distributed random elements having zero mean
560 and variance one.
561 
562 The arguments are handled the same as the arguments for @code{rand}.
563 
564 By default, @code{randn} uses the @nospell{Marsaglia and Tsang}
565 ``Ziggurat technique'' to transform from a uniform to a normal distribution.
566 
567 The class of the value returned can be controlled by a trailing
568 @qcode{"double"} or @qcode{"single"} argument. These are the only valid
569 classes.
570 
571 Reference: @nospell{G. Marsaglia and W.W. Tsang},
572 @cite{Ziggurat Method for Generating Random Variables},
573 J. Statistical Software, vol 5, 2000,
574 @url{https://www.jstatsoft.org/v05/i08/}
575 
576 @seealso{rand, rande, randg, randp}
577 @end deftypefn */)
578 {
579  return do_rand (args, args.length (), "randn", "normal");
580 }
581 
582 /*
583 %!test
584 %! ## Test a known fixed state
585 %! randn ("state", 1);
586 %! assert (randn (1, 6), [-2.666521678978671 -0.7381719971724564 1.507903992673601 0.6019427189162239 -0.450661261143348 -0.7054431351574116], 14*eps);
587 %!test
588 %! ## Test a known fixed seed
589 %! randn ("seed", 1);
590 %! assert (randn (1, 6), [-1.039402365684509 -1.25938892364502 0.1968704611063004 0.3874166905879974 -0.5976632833480835 -0.6615074276924133], 1e-6);
591 %!test
592 %! if (__random_statistical_tests__)
593 %! ## statistical tests may fail occasionally.
594 %! randn ("state", 12);
595 %! x = randn (100_000, 1);
596 %! assert (mean (x), 0, 0.01);
597 %! assert (var (x), 1, 0.02);
598 %! assert (skewness (x), 0, 0.02);
599 %! assert (kurtosis (x), 0, 0.04);
600 %! endif
601 %!test
602 %! if (__random_statistical_tests__)
603 %! ## statistical tests may fail occasionally.
604 %! randn ("seed", 12);
605 %! x = randn (100_000, 1);
606 %! assert (mean (x), 0, 0.01);
607 %! assert (var (x), 1, 0.02);
608 %! assert (skewness (x), 0, 0.02);
609 %! assert (kurtosis (x), 0, 0.04);
610 %! endif
611 */
612 
613 DEFUN (rande, args, ,
614  doc: /* -*- texinfo -*-
615 @deftypefn {} {} rande (@var{n})
616 @deftypefnx {} {} rande (@var{m}, @var{n}, @dots{})
617 @deftypefnx {} {} rande ([@var{m} @var{n} @dots{}])
618 @deftypefnx {} {@var{v} =} rande ("state")
619 @deftypefnx {} {} rande ("state", @var{v})
620 @deftypefnx {} {} rande ("state", "reset")
621 @deftypefnx {} {@var{v} =} rande ("seed")
622 @deftypefnx {} {} rande ("seed", @var{v})
623 @deftypefnx {} {} rande ("seed", "reset")
624 @deftypefnx {} {} rande (@dots{}, "single")
625 @deftypefnx {} {} rande (@dots{}, "double")
626 Return a matrix with exponentially distributed random elements.
627 
628 The arguments are handled the same as the arguments for @code{rand}.
629 
630 By default, @code{rande} uses the @nospell{Marsaglia and Tsang}
631 ``Ziggurat technique'' to transform from a uniform to an exponential
632 distribution.
633 
634 The class of the value returned can be controlled by a trailing
635 @qcode{"double"} or @qcode{"single"} argument. These are the only valid
636 classes.
637 
638 Reference: @nospell{G. Marsaglia and W.W. Tsang},
639 @cite{Ziggurat Method for Generating Random Variables},
640 J. Statistical Software, vol 5, 2000,
641 @url{https://www.jstatsoft.org/v05/i08/}
642 
643 @seealso{rand, randn, randg, randp}
644 @end deftypefn */)
645 {
646  return do_rand (args, args.length (), "rande", "exponential");
647 }
648 
649 /*
650 %!test
651 %! ## Test a known fixed state
652 %! rande ("state", 1);
653 %! assert (rande (1, 6), [3.602973885835625 0.1386190677555021 0.6743112889616958 0.4512830847258422 0.7255744741233175 0.3415969205292291], 2*eps);
654 %!test
655 %! ## Test a known fixed seed
656 %! rande ("seed", 1);
657 %! assert (rande (1, 6), [0.06492075175653866 1.717980206012726 0.4816154008731246 0.5231300676241517 0.103910739364359 1.668931916356087], 1e-6);
658 %!test
659 %! if (__random_statistical_tests__)
660 %! ## statistical tests may fail occasionally
661 %! rande ("state", 1);
662 %! x = rande (100_000, 1);
663 %! assert (min (x) > 0); # *** Please report this!!! ***
664 %! assert (mean (x), 1, 0.01);
665 %! assert (var (x), 1, 0.03);
666 %! assert (skewness (x), 2, 0.06);
667 %! assert (kurtosis (x), 6, 0.7);
668 %! endif
669 %!test
670 %! if (__random_statistical_tests__)
671 %! ## statistical tests may fail occasionally
672 %! rande ("seed", 1);
673 %! x = rande (100_000, 1);
674 %! assert (min (x)>0); # *** Please report this!!! ***
675 %! assert (mean (x), 1, 0.01);
676 %! assert (var (x), 1, 0.03);
677 %! assert (skewness (x), 2, 0.06);
678 %! assert (kurtosis (x), 6, 0.7);
679 %! endif
680 */
681 
682 DEFUN (randg, args, ,
683  doc: /* -*- texinfo -*-
684 @deftypefn {} {} randg (@var{a}, @var{n})
685 @deftypefnx {} {} randg (@var{a}, @var{m}, @var{n}, @dots{})
686 @deftypefnx {} {} randg (@var{a}, [@var{m} @var{n} @dots{}])
687 @deftypefnx {} {@var{v} =} randg ("state")
688 @deftypefnx {} {} randg ("state", @var{v})
689 @deftypefnx {} {} randg ("state", "reset")
690 @deftypefnx {} {@var{v} =} randg ("seed")
691 @deftypefnx {} {} randg ("seed", @var{v})
692 @deftypefnx {} {} randg ("seed", "reset")
693 @deftypefnx {} {} randg (@dots{}, "single")
694 @deftypefnx {} {} randg (@dots{}, "double")
695 
696 Return a matrix with @code{gamma (@var{a},1)} distributed random elements.
697 
698 The arguments are handled the same as the arguments for @code{rand}, except
699 for the argument @var{a}.
700 
701 This can be used to generate many distributions:
702 
703 @table @asis
704 @item @code{gamma (a, b)} for @code{a > -1}, @code{b > 0}
705 
706 @example
707 r = b * randg (a)
708 @end example
709 
710 @item @code{beta (a, b)} for @code{a > -1}, @code{b > -1}
711 
712 @example
713 @group
714 r1 = randg (a, 1)
715 r = r1 / (r1 + randg (b, 1))
716 @end group
717 @end example
718 
719 @item @code{Erlang (a, n)}
720 
721 @example
722 r = a * randg (n)
723 @end example
724 
725 @item @code{chisq (df)} for @code{df > 0}
726 
727 @example
728 r = 2 * randg (df / 2)
729 @end example
730 
731 @item @code{t (df)} for @code{0 < df < inf} (use randn if df is infinite)
732 
733 @example
734 r = randn () / sqrt (2 * randg (df / 2) / df)
735 @end example
736 
737 @item @code{F (n1, n2)} for @code{0 < n1}, @code{0 < n2}
738 
739 @example
740 @group
741 ## r1 equals 1 if n1 is infinite
742 r1 = 2 * randg (n1 / 2) / n1
743 ## r2 equals 1 if n2 is infinite
744 r2 = 2 * randg (n2 / 2) / n2
745 r = r1 / r2
746 @end group
747 @end example
748 
749 @item negative @code{binomial (n, p)} for @code{n > 0}, @code{0 < p <= 1}
750 
751 @example
752 r = randp ((1 - p) / p * randg (n))
753 @end example
754 
755 @item non-central @code{chisq (df, L)}, for @code{df >= 0} and @code{L > 0}
756 (use chisq if @code{L = 0})
757 
758 @example
759 @group
760 r = randp (L / 2)
761 r(r > 0) = 2 * randg (r(r > 0))
762 r(df > 0) += 2 * randg (df(df > 0)/2)
763 @end group
764 @end example
765 
766 @item @code{Dirichlet (a1, @dots{} ak)}
767 
768 @example
769 @group
770 r = (randg (a1), @dots{}, randg (ak))
771 r = r / sum (r)
772 @end group
773 @end example
774 
775 @end table
776 
777 The class of the value returned can be controlled by a trailing
778 @qcode{"double"} or @qcode{"single"} argument. These are the only valid
779 classes.
780 @seealso{rand, randn, rande, randp}
781 @end deftypefn */)
782 {
783  int nargin = args.length ();
784 
785  if (nargin < 1)
786  error ("randg: insufficient arguments");
787 
788  return do_rand (args, nargin, "randg", "gamma", true);
789 }
790 
791 /*
792 %!test
793 %! randg ("state", 12);
794 %! assert (randg ([-inf, -1, 0, inf, nan]), [nan, nan, nan, nan, nan]); # *** Please report
795 
796 %!test
797 %! ## Test a known fixed state
798 %! randg ("state", 1);
799 %! assert (randg (0.1, 1, 6), [0.0103951513331241 8.335671459898252e-05 0.00138691397249762 0.000587308416993855 0.495590518784736 2.3921917414795e-12], eps);
800 %!test
801 %! ## Test a known fixed state
802 %! randg ("state", 1);
803 %! assert (randg (0.95, 1, 6), [3.099382433255327 0.3974529788871218 0.644367450750855 1.143261091802246 1.964111762696822 0.04011915547957939], 12*eps);
804 %!test
805 %! ## Test a known fixed state
806 %! randg ("state", 1);
807 %! assert (randg (1, 1, 6), [0.2273389379645993 1.288822625058359 0.2406335209340746 1.218869553370733 1.024649860162554 0.09631230343599533], 40*eps);
808 %!test
809 %! ## Test a known fixed state
810 %! randg ("state", 1);
811 %! assert (randg (10, 1, 6), [3.520369644331133 15.15369864472106 8.332112081991205 8.406211067432674 11.81193475187611 10.88792728177059], 56*eps);
812 %!test
813 %! ## Test a known fixed state
814 %! randg ("state", 1);
815 %! assert (randg (100, 1, 6), [75.34570255262264 115.4911985594699 95.23493031356388 95.48926019250911 106.2397448229803 103.4813150404118], 256*eps);
816 %!test
817 %! ## Test a known fixed seed
818 %! randg ("seed", 1);
819 %! assert (randg (0.1, 1, 6), [0.07144210487604141 0.460641473531723 0.4749028384685516 0.06823389977216721 0.000293838675133884 1.802567535340305e-12], 1e-6);
820 %!test
821 %! ## Test a known fixed seed
822 %! randg ("seed", 1);
823 %! assert (randg (0.95, 1, 6), [1.664905071258545 1.879976987838745 1.905677795410156 0.9948706030845642 0.5606933236122131 0.0766092911362648], 1e-6);
824 %!test
825 %! ## Test a known fixed seed
826 %! randg ("seed", 1);
827 %! assert (randg (1, 1, 6), [0.03512085229158401 0.6488978862762451 0.8114678859710693 0.1666885763406754 1.60791552066803 1.90356981754303], 1e-6);
828 %!test
829 %! ## Test a known fixed seed
830 %! randg ("seed", 1);
831 %! assert (randg (10, 1, 6), [6.566435813903809 10.11648464202881 10.73162078857422 7.747178077697754 6.278522491455078 6.240195751190186], 1e-5);
832 %!test
833 %! ## Test a known fixed seed
834 %! randg ("seed", 1);
835 %! assert (randg (100, 1, 6), [89.40208435058594 101.4734725952148 103.4020004272461 93.62763214111328 88.33104705810547 88.1871337890625], 1e-4);
836 %!test
837 %! ## Test out-of-bounds values produce NaN w/old-style generators & floats
838 %! randg ("seed", 1);
839 %! result = randg ([-2 Inf], "single");
840 %! assert (result, single ([NaN NaN]));
841 
842 %!test
843 %! if (__random_statistical_tests__)
844 %! ## statistical tests may fail occasionally.
845 %! randg ("state", 12);
846 %! a = 0.1;
847 %! x = randg (a, 100_000, 1);
848 %! assert (mean (x), a, 0.01);
849 %! assert (var (x), a, 0.01);
850 %! assert (skewness (x), 2/sqrt (a), 1);
851 %! assert (kurtosis (x), 6/a, 50);
852 %! endif
853 %!test
854 %! if (__random_statistical_tests__)
855 %! ## statistical tests may fail occasionally.
856 %! randg ("state", 12);
857 %! a = 0.95;
858 %! x = randg (a, 100_000, 1);
859 %! assert (mean (x), a, 0.01);
860 %! assert (var (x), a, 0.04);
861 %! assert (skewness (x), 2/sqrt (a), 0.2);
862 %! assert (kurtosis (x), 6/a, 2);
863 %! endif
864 %!test
865 %! if (__random_statistical_tests__)
866 %! ## statistical tests may fail occasionally.
867 %! randg ("state", 12);
868 %! a = 1;
869 %! x = randg (a, 100_000, 1);
870 %! assert (mean (x), a, 0.01);
871 %! assert (var (x), a, 0.04);
872 %! assert (skewness (x), 2/sqrt (a), 0.2);
873 %! assert (kurtosis (x), 6/a, 2);
874 %! endif
875 %!test
876 %! if (__random_statistical_tests__)
877 %! ## statistical tests may fail occasionally.
878 %! randg ("state", 12);
879 %! a = 10;
880 %! x = randg (a, 100_000, 1);
881 %! assert (mean (x), a, 0.1);
882 %! assert (var (x), a, 0.5);
883 %! assert (skewness (x), 2/sqrt (a), 0.1);
884 %! assert (kurtosis (x), 6/a, 0.5);
885 %! endif
886 %!test
887 %! if (__random_statistical_tests__)
888 %! ## statistical tests may fail occasionally.
889 %! randg ("state", 12);
890 %! a = 100;
891 %! x = randg (a, 100_000, 1);
892 %! assert (mean (x), a, 0.2);
893 %! assert (var (x), a, 2);
894 %! assert (skewness (x), 2/sqrt (a), 0.05);
895 %! assert (kurtosis (x), 6/a, 0.2);
896 %! endif
897 %!test
898 %! randg ("seed", 12);
899 %!assert (randg ([-inf, -1, 0, inf, nan]), [nan, nan, nan, nan, nan]) # *** Please report
900 %!test
901 %! if (__random_statistical_tests__)
902 %! ## statistical tests may fail occasionally.
903 %! randg ("seed", 12);
904 %! a = 0.1;
905 %! x = randg (a, 100_000, 1);
906 %! assert (mean (x), a, 0.01);
907 %! assert (var (x), a, 0.01);
908 %! assert (skewness (x), 2/sqrt (a), 1);
909 %! assert (kurtosis (x), 6/a, 50);
910 %! endif
911 %!test
912 %! if (__random_statistical_tests__)
913 %! ## statistical tests may fail occasionally.
914 %! randg ("seed", 12);
915 %! a = 0.95;
916 %! x = randg (a, 100_000, 1);
917 %! assert (mean (x), a, 0.01);
918 %! assert (var (x), a, 0.04);
919 %! assert (skewness (x), 2/sqrt (a), 0.2);
920 %! assert (kurtosis (x), 6/a, 2);
921 %! endif
922 %!test
923 %! if (__random_statistical_tests__)
924 %! ## statistical tests may fail occasionally.
925 %! randg ("seed", 12);
926 %! a = 1;
927 %! x = randg (a, 100_000, 1);
928 %! assert (mean (x), a, 0.01);
929 %! assert (var (x), a, 0.04);
930 %! assert (skewness (x), 2/sqrt (a), 0.2);
931 %! assert (kurtosis (x), 6/a, 2);
932 %! endif
933 %!test
934 %! if (__random_statistical_tests__)
935 %! ## statistical tests may fail occasionally.
936 %! randg ("seed", 12);
937 %! a = 10;
938 %! x = randg (a, 100_000, 1);
939 %! assert (mean (x), a, 0.1);
940 %! assert (var (x), a, 0.5);
941 %! assert (skewness (x), 2/sqrt (a), 0.1);
942 %! assert (kurtosis (x), 6/a, 0.5);
943 %! endif
944 %!test
945 %! if (__random_statistical_tests__)
946 %! ## statistical tests may fail occasionally.
947 %! randg ("seed", 12);
948 %! a = 100;
949 %! x = randg (a, 100_000, 1);
950 %! assert (mean (x), a, 0.2);
951 %! assert (var (x), a, 2);
952 %! assert (skewness (x), 2/sqrt (a), 0.05);
953 %! assert (kurtosis (x), 6/a, 0.2);
954 %! endif
955 */
956 
957 DEFUN (randp, args, ,
958  doc: /* -*- texinfo -*-
959 @deftypefn {} {} randp (@var{l}, @var{n})
960 @deftypefnx {} {} randp (@var{l}, @var{m}, @var{n}, @dots{})
961 @deftypefnx {} {} randp (@var{l}, [@var{m} @var{n} @dots{}])
962 @deftypefnx {} {@var{v} =} randp ("state")
963 @deftypefnx {} {} randp ("state", @var{v})
964 @deftypefnx {} {} randp ("state", "reset")
965 @deftypefnx {} {@var{v} =} randp ("seed")
966 @deftypefnx {} {} randp ("seed", @var{v})
967 @deftypefnx {} {} randp ("seed", "reset")
968 @deftypefnx {} {} randp (@dots{}, "single")
969 @deftypefnx {} {} randp (@dots{}, "double")
970 Return a matrix with Poisson distributed random elements with mean value
971 parameter given by the first argument, @var{l}.
972 
973 The arguments are handled the same as the arguments for @code{rand}, except
974 for the argument @var{l}.
975 
976 Five different algorithms are used depending on the range of @var{l} and
977 whether or not @var{l} is a scalar or a matrix.
978 
979 @table @asis
980 @item For scalar @var{l} @leq{} 12, use direct method.
981 W.H. Press, et al., @cite{Numerical Recipes in C},
982 Cambridge University Press, 1992.
983 
984 @item For scalar @var{l} > 12, use rejection method.[1]
985 W.H. Press, et al., @cite{Numerical Recipes in C},
986 Cambridge University Press, 1992.
987 
988 @item For matrix @var{l} @leq{} 10, use inversion method.[2]
989 @nospell{E. Stadlober, et al., WinRand source code}, available via FTP.
990 
991 @item For matrix @var{l} > 10, use patchwork rejection method.
992 @nospell{E. Stadlober, et al., WinRand source code}, available via FTP, or
993 @nospell{H. Zechner}, @cite{Efficient sampling from continuous and discrete
994 unimodal distributions}, Doctoral Dissertation, 156pp., Technical
995 University @nospell{Graz}, Austria, 1994.
996 
997 @item For @var{l} > 1e8, use normal approximation.
998 @nospell{L. Montanet}, et al., @cite{Review of Particle Properties},
999 Physical Review D 50 p1284, 1994.
1000 @end table
1001 
1002 The class of the value returned can be controlled by a trailing
1003 @qcode{"double"} or @qcode{"single"} argument. These are the only valid
1004 classes.
1005 @seealso{rand, randn, rande, randg}
1006 @end deftypefn */)
1007 {
1008  int nargin = args.length ();
1009 
1010  if (nargin < 1)
1011  error ("randp: insufficient arguments");
1012 
1013  return do_rand (args, nargin, "randp", "poisson", true);
1014 }
1015 
1016 /*
1017 %!test
1018 %! randp ("state", 12);
1019 %! assert (randp ([-inf, -1, 0, inf, nan]), [nan, nan, 0, nan, nan]); # *** Please report
1020 %!test
1021 %! ## Test a known fixed state
1022 %! randp ("state", 1);
1023 %! assert (randp (5, 1, 6), [5 5 3 7 7 3]);
1024 %!test
1025 %! ## Test a known fixed state
1026 %! randp ("state", 1);
1027 %! assert (randp (15, 1, 6), [13 15 8 18 18 15]);
1028 %!test
1029 %! ## Test a known fixed state
1030 %! randp ("state", 1);
1031 %! assert (randp (1e9, 1, 6), [999915677 999976657 1000047684 1000019035 999985749 999977692], -1e-6);
1032 %!test
1033 %! ## Test a known fixed seed
1034 %! randp ("seed", 1);
1035 %! %%assert (randp (5, 1, 6), [8 2 3 6 6 8])
1036 %! assert (randp (5, 1, 5), [8 2 3 6 6]);
1037 %!test
1038 %! ## Test a known fixed seed
1039 %! randp ("seed", 1);
1040 %! assert (randp (15, 1, 6), [15 16 12 10 10 12]);
1041 %!test
1042 %! ## Test a known fixed seed
1043 %! randp ("seed", 1);
1044 %! assert (randp (1e9, 1, 6), [1000006208 1000012224 999981120 999963520 999963072 999981440], -1e-6);
1045 %!test
1046 %! if (__random_statistical_tests__)
1047 %! ## statistical tests may fail occasionally.
1048 %! randp ("state", 12);
1049 %! for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
1050 %! x = randp (a (1), 100_000, 1);
1051 %! assert (min (x) >= 0); # *** Please report this!!! ***
1052 %! assert (mean (x), a(1), a(2));
1053 %! assert (var (x), a(1), 0.02*a(1));
1054 %! assert (skewness (x), 1/sqrt (a(1)), a(3));
1055 %! assert (kurtosis (x), 1/a(1), 3*a(3));
1056 %! endfor
1057 %! endif
1058 %!test
1059 %! if (__random_statistical_tests__)
1060 %! ## statistical tests may fail occasionally.
1061 %! randp ("state", 12);
1062 %! for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
1063 %! x = randp (a(1)*ones (100_000, 1), 100_000, 1);
1064 %! assert (min (x) >= 0); # *** Please report this!!! ***
1065 %! assert (mean (x), a(1), a(2));
1066 %! assert (var (x), a(1), 0.02*a(1));
1067 %! assert (skewness (x), 1/sqrt (a(1)), a(3));
1068 %! assert (kurtosis (x), 1/a(1), 3*a(3));
1069 %! endfor
1070 %! endif
1071 %!test
1072 %! randp ("seed", 12);
1073 %! assert (randp ([-inf, -1, 0, inf, nan]), [nan, nan, 0, nan, nan]); # *** Please report
1074 %!test
1075 %! if (__random_statistical_tests__)
1076 %! ## statistical tests may fail occasionally.
1077 %! randp ("seed", 12);
1078 %! for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
1079 %! x = randp (a(1), 100_000, 1);
1080 %! assert (min (x) >= 0); # *** Please report this!!! ***
1081 %! assert (mean (x), a(1), a(2));
1082 %! assert (var (x), a(1), 0.02*a(1));
1083 %! assert (skewness (x), 1/sqrt (a(1)), a(3));
1084 %! assert (kurtosis (x), 1/a(1), 3*a(3));
1085 %! endfor
1086 %! endif
1087 %!test
1088 %! if (__random_statistical_tests__)
1089 %! ## statistical tests may fail occasionally.
1090 %! randp ("seed", 12);
1091 %! for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
1092 %! x = randp (a(1)*ones (100_000, 1), 100_000, 1);
1093 %! assert (min (x) >= 0); # *** Please report this!!! ***
1094 %! assert (mean (x), a(1), a(2));
1095 %! assert (var (x), a(1), 0.02*a(1));
1096 %! assert (skewness (x), 1/sqrt (a(1)), a(3));
1097 %! assert (kurtosis (x), 1/a(1), 3*a(3));
1098 %! endfor
1099 %! endif
1100 */
1101 
1102 DEFUN (randperm, args, ,
1103  doc: /* -*- texinfo -*-
1104 @deftypefn {} {} randperm (@var{n})
1105 @deftypefnx {} {} randperm (@var{n}, @var{m})
1106 Return a row vector containing a random permutation of @code{1:@var{n}}.
1107 
1108 If @var{m} is supplied, return @var{m} unique entries, sampled without
1109 replacement from @code{1:@var{n}}.
1110 
1111 The complexity is O(@var{n}) in memory and O(@var{m}) in time, unless
1112 @var{m} < @var{n}/5, in which case O(@var{m}) memory is used as well. The
1113 randomization is performed using rand(). All permutations are equally
1114 likely.
1115 @seealso{perms}
1116 @end deftypefn */)
1117 {
1118  int nargin = args.length ();
1119 
1120  if (nargin < 1 || nargin > 2)
1121  print_usage ();
1122 
1123  octave_idx_type n = args(0).idx_type_value (true);
1124  octave_idx_type m = (nargin == 2) ? args(1).idx_type_value (true) : n;
1125 
1126  if (m < 0 || n < 0)
1127  error ("randperm: M and N must be non-negative");
1128 
1129  if (m > n)
1130  error ("randperm: M must be less than or equal to N");
1131 
1132  // Quick and dirty heuristic to decide if we allocate or not the
1133  // whole vector for tracking the truncated shuffle.
1134  bool short_shuffle = m < n/5;
1135 
1136  // Generate random numbers.
1138  double *rvec = r.fortran_vec ();
1139 
1140  octave_idx_type idx_len = (short_shuffle ? m : n);
1142  try
1143  {
1144  idx = Array<octave_idx_type> (dim_vector (1, idx_len));
1145  }
1146  catch (const std::bad_alloc&)
1147  {
1148  // Looks like n is too big and short_shuffle is false.
1149  // Let's try again, but this time with the alternative.
1150  idx_len = m;
1151  short_shuffle = true;
1152  idx = Array<octave_idx_type> (dim_vector (1, idx_len));
1153  }
1154 
1155  octave_idx_type *ivec = idx.fortran_vec ();
1156 
1157  for (octave_idx_type i = 0; i < idx_len; i++)
1158  ivec[i] = i;
1159 
1160  if (short_shuffle)
1161  {
1162  std::unordered_map<octave_idx_type, octave_idx_type> map (m);
1163 
1164  // Perform the Knuth shuffle only keeping track of moved
1165  // entries in the map
1166  for (octave_idx_type i = 0; i < m; i++)
1167  {
1168  octave_idx_type k = i + std::floor (rvec[i] * (n - i));
1169 
1170  // For shuffling first m entries, no need to use extra storage
1171  if (k < m)
1172  {
1173  std::swap (ivec[i], ivec[k]);
1174  }
1175  else
1176  {
1177  if (map.find (k) == map.end ())
1178  map[k] = k;
1179 
1180  std::swap (ivec[i], map[k]);
1181  }
1182  }
1183  }
1184  else
1185  {
1186  // Perform the Knuth shuffle of the first m entries
1187  for (octave_idx_type i = 0; i < m; i++)
1188  {
1189  octave_idx_type k = i + std::floor (rvec[i] * (n - i));
1190  std::swap (ivec[i], ivec[k]);
1191  }
1192  }
1193 
1194  // Convert to doubles, reusing r.
1195  for (octave_idx_type i = 0; i < m; i++)
1196  rvec[i] = ivec[i] + 1;
1197 
1198  if (m < n)
1199  idx.resize (dim_vector (1, m));
1200 
1201  // Now create an array object with a cached idx_vector.
1202  return ovl (new octave_matrix (r, idx_vector (idx)));
1203 }
1204 
1205 /*
1206 %!assert (sort (randperm (20)), 1:20)
1207 %!assert (length (randperm (20,10)), 10)
1208 
1209 ## Test biggish N
1210 %!assert <*39378> (length (randperm (30_000^2, 100_000)), 100_000)
1211 
1212 %!test
1213 %! rand ("seed", 0);
1214 %! for i = 1:100
1215 %! p = randperm (305, 30);
1216 %! assert (length (unique (p)), 30);
1217 %! endfor
1218 */
template class OCTAVE_API Array< octave_idx_type >
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Definition: Array.cc:1011
T & xelem(octave_idx_type n)
Size of the specified dimension.
Definition: Array.h:469
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:377
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:453
const T * fortran_vec(void) const
Size of the specified dimension.
Definition: Array.h:583
Definition: Range.h:40
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
void resize(int n, int fill_value=0)
Definition: dim-vector.h:349
void chop_trailing_singletons(void)
Definition: dim-vector.h:241
void add_fcn(void(*fcn)(Params...), Args &&... args)
static NDArray nd_array(const dim_vector &dims, double a=1.0)
Definition: oct-rand.h:170
static uint32NDArray state(const std::string &d="")
Definition: oct-rand.h:78
static std::string distribution(void)
Definition: oct-rand.h:99
static double seed(void)
Definition: oct-rand.h:57
static void normal_distribution(void)
Definition: oct-rand.h:118
static void poisson_distribution(void)
Definition: oct-rand.h:130
static double scalar(double a=1.0)
Definition: oct-rand.h:143
static FloatNDArray float_nd_array(const dim_vector &dims, float a=1.0)
Definition: oct-rand.h:177
static float float_scalar(float a=1.0)
Definition: oct-rand.h:150
static void reset(void)
Definition: oct-rand.h:71
static void exponential_distribution(void)
Definition: oct-rand.h:124
static void gamma_distribution(void)
Definition: oct-rand.h:136
static void uniform_distribution(void)
Definition: oct-rand.h:112
octave_idx_type idx_type_value(bool req_int=false, bool frc_str_conv=false) const
bool is_scalar_type(void) const
Definition: ov.h:697
Range range_value(void) const
Definition: ov.h:938
bool is_string(void) const
Definition: ov.h:593
Array< octave_idx_type > octave_idx_type_vector_value(bool req_int=false, bool frc_str_conv=false, bool frc_vec_conv=false) const
std::string string_value(bool force=false) const
Definition: ov.h:927
bool is_matrix_type(void) const
Definition: ov.h:700
bool is_range(void) const
Definition: ov.h:602
OCTINTERP_API void print_usage(void)
Definition: defun.cc:53
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
void error(const char *fmt,...)
Definition: error.cc:968
void err_wrong_type_arg(const char *name, const char *s)
Definition: errwarn.cc:166
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
T octave_idx_type m
Definition: mx-inlines.cc:773
octave_idx_type n
Definition: mx-inlines.cc:753
T * r
Definition: mx-inlines.cc:773
bool isinf(double x)
Definition: lo-mappers.h:203
octave_idx_type nint_big(double x)
Definition: lo-mappers.cc:184
std::complex< T > floor(const std::complex< T > &x)
Definition: lo-mappers.h:130
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211
static octave_value do_rand(const octave_value_list &args, int nargin, const char *fcn, const std::string &distribution, bool additional_arg=false)
Definition: rand.cc:82
static std::string current_distribution
Definition: rand.cc:544
F77_RET_T len
Definition: xerbla.cc:61