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