Mercurial > octave
comparison src/DLD-FUNCTIONS/rand.cc @ 10709:92a85ed5b86e
Don't special case color_property type when emitting factory default (bug #30118)
author | David Bateman <dbateman@free.fr> |
---|---|
date | Wed, 16 Jun 2010 23:27:58 +0200 |
parents | a8ce6bdecce5 |
children | d1f920d1ce0c |
comparison
equal
deleted
inserted
replaced
10708:2786b7ae3f80 | 10709:92a85ed5b86e |
---|---|
241 double d = args(idx+1).double_value (); | 241 double d = args(idx+1).double_value (); |
242 | 242 |
243 if (! error_state) | 243 if (! error_state) |
244 octave_rand::seed (d); | 244 octave_rand::seed (d); |
245 } | 245 } |
246 else if (args(idx+1).is_string () | |
247 && args(idx+1).string_value() == "reset") | |
248 octave_rand::reset (); | |
246 else | 249 else |
247 error ("%s: seed must be a real scalar", fcn); | 250 error ("%s: seed must be a real scalar", fcn); |
248 } | 251 } |
249 else if (ts == "state" || ts == "twister") | 252 else if (ts == "state" || ts == "twister") |
250 { | 253 { |
251 ColumnVector s = | 254 if (args(idx+1).is_string () |
252 ColumnVector (args(idx+1).vector_value(false, true)); | 255 && args(idx+1).string_value() == "reset") |
253 | 256 octave_rand::reset (fcn); |
254 if (! error_state) | 257 else |
255 octave_rand::state (s, fcn); | 258 { |
259 ColumnVector s = | |
260 ColumnVector (args(idx+1).vector_value(false, true)); | |
261 | |
262 if (! error_state) | |
263 octave_rand::state (s, fcn); | |
264 } | |
256 } | 265 } |
257 else | 266 else |
258 error ("%s: unrecognized string argument", fcn); | 267 error ("%s: unrecognized string argument", fcn); |
259 } | 268 } |
260 else | 269 else |
312 DEFUN_DLD (rand, args, , | 321 DEFUN_DLD (rand, args, , |
313 "-*- texinfo -*-\n\ | 322 "-*- texinfo -*-\n\ |
314 @deftypefn {Loadable Function} {} rand (@var{x})\n\ | 323 @deftypefn {Loadable Function} {} rand (@var{x})\n\ |
315 @deftypefnx {Loadable Function} {} rand (@var{n}, @var{m})\n\ | 324 @deftypefnx {Loadable Function} {} rand (@var{n}, @var{m})\n\ |
316 @deftypefnx {Loadable Function} {} rand (\"state\", @var{x})\n\ | 325 @deftypefnx {Loadable Function} {} rand (\"state\", @var{x})\n\ |
326 @deftypefnx {Loadable Function} {} rand (\"state\", \"reset\")\n\ | |
317 @deftypefnx {Loadable Function} {} rand (\"seed\", @var{x})\n\ | 327 @deftypefnx {Loadable Function} {} rand (\"seed\", @var{x})\n\ |
328 @deftypefnx {Loadable Function} {} rand (\"seed\", \"reset\")\n\ | |
318 Return a matrix with random elements uniformly distributed on the\n\ | 329 Return a matrix with random elements uniformly distributed on the\n\ |
319 interval (0, 1). The arguments are handled the same as the arguments\n\ | 330 interval (0, 1). The arguments are handled the same as the arguments\n\ |
320 for @code{eye}.\n\ | 331 for @code{eye}.\n\ |
321 \n\ | 332 \n\ |
322 You can query the state of the random number generator using the\n\ | 333 You can query the state of the random number generator using the\n\ |
374 \n\ | 385 \n\ |
375 However, it should be noted that querying the seed will not cause\n\ | 386 However, it should be noted that querying the seed will not cause\n\ |
376 @code{rand} to use the old generators, only setting the seed will.\n\ | 387 @code{rand} to use the old generators, only setting the seed will.\n\ |
377 To cause @code{rand} to once again use the new generators, the\n\ | 388 To cause @code{rand} to once again use the new generators, the\n\ |
378 keyword \"state\" should be used to reset the state of the @code{rand}.\n\ | 389 keyword \"state\" should be used to reset the state of the @code{rand}.\n\ |
390 \n\ | |
391 The state or seed of the generator can be reset to a new random value\n\ | |
392 using the \"reset\" keyword.\n\ | |
379 @seealso{randn, rande, randg, randp}\n\ | 393 @seealso{randn, rande, randg, randp}\n\ |
380 @end deftypefn") | 394 @end deftypefn") |
381 { | 395 { |
382 octave_value retval; | 396 octave_value retval; |
383 | 397 |
472 DEFUN_DLD (randn, args, , | 486 DEFUN_DLD (randn, args, , |
473 "-*- texinfo -*-\n\ | 487 "-*- texinfo -*-\n\ |
474 @deftypefn {Loadable Function} {} randn (@var{x})\n\ | 488 @deftypefn {Loadable Function} {} randn (@var{x})\n\ |
475 @deftypefnx {Loadable Function} {} randn (@var{n}, @var{m})\n\ | 489 @deftypefnx {Loadable Function} {} randn (@var{n}, @var{m})\n\ |
476 @deftypefnx {Loadable Function} {} randn (\"state\", @var{x})\n\ | 490 @deftypefnx {Loadable Function} {} randn (\"state\", @var{x})\n\ |
491 @deftypefnx {Loadable Function} {} randn (\"state\", \"reset\")\n\ | |
477 @deftypefnx {Loadable Function} {} randn (\"seed\", @var{x})\n\ | 492 @deftypefnx {Loadable Function} {} randn (\"seed\", @var{x})\n\ |
493 @deftypefnx {Loadable Function} {} randn (\"seed\", \"reset\")\n\ | |
478 Return a matrix with normally distributed random\n\ | 494 Return a matrix with normally distributed random\n\ |
479 elements having zero mean and variance one. The arguments are\n\ | 495 elements having zero mean and variance one. The arguments are\n\ |
480 handled the same as the arguments for @code{rand}.\n\ | 496 handled the same as the arguments for @code{rand}.\n\ |
481 \n\ | 497 \n\ |
482 By default, @code{randn} uses the Marsaglia and Tsang ``Ziggurat technique'' to\n\ | 498 By default, @code{randn} uses the Marsaglia and Tsang ``Ziggurat technique'' to\n\ |
545 DEFUN_DLD (rande, args, , | 561 DEFUN_DLD (rande, args, , |
546 "-*- texinfo -*-\n\ | 562 "-*- texinfo -*-\n\ |
547 @deftypefn {Loadable Function} {} rande (@var{x})\n\ | 563 @deftypefn {Loadable Function} {} rande (@var{x})\n\ |
548 @deftypefnx {Loadable Function} {} rande (@var{n}, @var{m})\n\ | 564 @deftypefnx {Loadable Function} {} rande (@var{n}, @var{m})\n\ |
549 @deftypefnx {Loadable Function} {} rande (\"state\", @var{x})\n\ | 565 @deftypefnx {Loadable Function} {} rande (\"state\", @var{x})\n\ |
566 @deftypefnx {Loadable Function} {} rande (\"state\", \"reset\")\n\ | |
550 @deftypefnx {Loadable Function} {} rande (\"seed\", @var{x})\n\ | 567 @deftypefnx {Loadable Function} {} rande (\"seed\", @var{x})\n\ |
568 @deftypefnx {Loadable Function} {} rande (\"seed\", \"reset\")\n\ | |
551 Return a matrix with exponentially distributed random elements. The\n\ | 569 Return a matrix with exponentially distributed random elements. The\n\ |
552 arguments are handled the same as the arguments for @code{rand}.\n\ | 570 arguments are handled the same as the arguments for @code{rand}.\n\ |
553 \n\ | 571 \n\ |
554 By default, @code{randn} uses the Marsaglia and Tsang ``Ziggurat technique'' to\n\ | 572 By default, @code{randn} uses the Marsaglia and Tsang ``Ziggurat technique'' to\n\ |
555 transform from a uniform to a exponential distribution. (G. Marsaglia and\n\ | 573 transform from a uniform to a exponential distribution. (G. Marsaglia and\n\ |
618 DEFUN_DLD (randg, args, , | 636 DEFUN_DLD (randg, args, , |
619 "-*- texinfo -*-\n\ | 637 "-*- texinfo -*-\n\ |
620 @deftypefn {Loadable Function} {} randg (@var{a}, @var{x})\n\ | 638 @deftypefn {Loadable Function} {} randg (@var{a}, @var{x})\n\ |
621 @deftypefnx {Loadable Function} {} randg (@var{a}, @var{n}, @var{m})\n\ | 639 @deftypefnx {Loadable Function} {} randg (@var{a}, @var{n}, @var{m})\n\ |
622 @deftypefnx {Loadable Function} {} randg (\"state\", @var{x})\n\ | 640 @deftypefnx {Loadable Function} {} randg (\"state\", @var{x})\n\ |
641 @deftypefnx {Loadable Function} {} randg (\"state\", \"reset\")\n\ | |
623 @deftypefnx {Loadable Function} {} randg (\"seed\", @var{x})\n\ | 642 @deftypefnx {Loadable Function} {} randg (\"seed\", @var{x})\n\ |
643 @deftypefnx {Loadable Function} {} randg (\"seed\", \"reset\")\n\ | |
624 Return a matrix with @code{gamma(@var{a},1)} distributed random elements.\n\ | 644 Return a matrix with @code{gamma(@var{a},1)} distributed random elements.\n\ |
625 The arguments are handled the same as the arguments for @code{rand},\n\ | 645 The arguments are handled the same as the arguments for @code{rand},\n\ |
626 except for the argument @var{a}.\n\ | 646 except for the argument @var{a}.\n\ |
627 \n\ | 647 \n\ |
628 This can be used to generate many distributions:\n\ | 648 This can be used to generate many distributions:\n\ |
868 DEFUN_DLD (randp, args, , | 888 DEFUN_DLD (randp, args, , |
869 "-*- texinfo -*-\n\ | 889 "-*- texinfo -*-\n\ |
870 @deftypefn {Loadable Function} {} randp (@var{l}, @var{x})\n\ | 890 @deftypefn {Loadable Function} {} randp (@var{l}, @var{x})\n\ |
871 @deftypefnx {Loadable Function} {} randp (@var{l}, @var{n}, @var{m})\n\ | 891 @deftypefnx {Loadable Function} {} randp (@var{l}, @var{n}, @var{m})\n\ |
872 @deftypefnx {Loadable Function} {} randp (\"state\", @var{x})\n\ | 892 @deftypefnx {Loadable Function} {} randp (\"state\", @var{x})\n\ |
893 @deftypefnx {Loadable Function} {} randp (\"state\", \"reset\")\n\ | |
873 @deftypefnx {Loadable Function} {} randp (\"seed\", @var{x})\n\ | 894 @deftypefnx {Loadable Function} {} randp (\"seed\", @var{x})\n\ |
895 @deftypefnx {Loadable Function} {} randp (\"seed\", \"reset\")\n\ | |
874 Return a matrix with Poisson distributed random elements with mean value\n\ | 896 Return a matrix with Poisson distributed random elements with mean value\n\ |
875 parameter given by the first argument, @var{l}. The arguments\n\ | 897 parameter given by the first argument, @var{l}. The arguments\n\ |
876 are handled the same as the arguments for @code{rand}, except for the\n\ | 898 are handled the same as the arguments for @code{rand}, except for the\n\ |
877 argument @var{l}.\n\ | 899 argument @var{l}.\n\ |
878 \n\ | 900 \n\ |