comparison libinterp/corefcn/rand.cc @ 17336:b81b9d079515

Use '##' for comments which stand alone on a line. * libinterp/corefcn/besselj.cc, libinterp/corefcn/conv2.cc, libinterp/corefcn/pinv.cc, libinterp/corefcn/rand.cc, libinterp/corefcn/regexp.cc, libinterp/corefcn/sqrtm.cc, libinterp/dldfcn/qr.cc, libinterp/parse-tree/pt-eval.cc, scripts/general/cplxpair.m, scripts/general/repmat.m, scripts/help/doc.m, scripts/help/doc_cache_create.m, scripts/image/colorcube.m, scripts/image/hsv2rgb.m, scripts/image/image.m, scripts/io/strread.m, scripts/io/textscan.m, scripts/miscellaneous/bzip2.m, scripts/miscellaneous/edit.m, scripts/miscellaneous/gzip.m, scripts/optimization/__all_opts__.m, scripts/optimization/fminbnd.m, scripts/optimization/sqp.m, scripts/pkg/private/get_forge_pkg.m, scripts/plot/area.m, scripts/plot/stemleaf.m, scripts/plot/surfc.m, scripts/plot/uiresume.m, scripts/plot/zlabel.m, scripts/polynomial/mkpp.m, scripts/polynomial/ppval.m, scripts/set/intersect.m, scripts/signal/freqz.m, scripts/sparse/pcg.m, scripts/sparse/pcr.m, scripts/sparse/svds.m, scripts/sparse/treelayout.m, scripts/specfun/ellipke.m, scripts/special-matrix/toeplitz.m, scripts/strings/dec2base.m, scripts/strings/strsplit.m, scripts/testfun/test.m, test/build-sparse-tests.sh, test/index.tst, test/system.tst: Use '##' for comments which stand alone on a line.
author Rik <rik@octave.org>
date Wed, 28 Aug 2013 08:27:38 -0700
parents bc924baa2c4e
children 0b7f5c56f853
comparison
equal deleted inserted replaced
17335:583306fe7e4f 17336:b81b9d079515
47 #include "utils.h" 47 #include "utils.h"
48 #include "ov-re-mat.h" 48 #include "ov-re-mat.h"
49 49
50 /* 50 /*
51 %!shared __random_statistical_tests__ 51 %!shared __random_statistical_tests__
52 %! # Flag whether the statistical tests should be run in "make check" or not 52 %! ## Flag whether the statistical tests should be run in "make check" or not
53 %! __random_statistical_tests__ = 0; 53 %! __random_statistical_tests__ = 0;
54 */ 54 */
55 55
56 static octave_value 56 static octave_value
57 do_rand (const octave_value_list& args, int nargin, const char *fcn, 57 do_rand (const octave_value_list& args, int nargin, const char *fcn,
500 %! assert (x, z); 500 %! assert (x, z);
501 */ 501 */
502 502
503 /* 503 /*
504 %!test 504 %!test
505 %! # Test fixed state 505 %! ## Test fixed state
506 %! rand ("state", 1); 506 %! rand ("state", 1);
507 %! assert (rand (1,6), [0.1343642441124013 0.8474337369372327 0.763774618976614 0.2550690257394218 0.495435087091941 0.4494910647887382], 1e-6); 507 %! assert (rand (1,6), [0.1343642441124013 0.8474337369372327 0.763774618976614 0.2550690257394218 0.495435087091941 0.4494910647887382], 1e-6);
508 %!test 508 %!test
509 %! # Test fixed seed 509 %! ## Test fixed seed
510 %! rand ("seed", 1); 510 %! rand ("seed", 1);
511 %! assert (rand (1,6), [0.8668024251237512 0.9126510815694928 0.09366085007786751 0.1664607301354408 0.7408077004365623 0.7615650338120759], 1e-6); 511 %! assert (rand (1,6), [0.8668024251237512 0.9126510815694928 0.09366085007786751 0.1664607301354408 0.7408077004365623 0.7615650338120759], 1e-6);
512 %!test 512 %!test
513 %! if (__random_statistical_tests__) 513 %! if (__random_statistical_tests__)
514 %! # statistical tests may fail occasionally. 514 %! ## statistical tests may fail occasionally.
515 %! rand ("state", 12); 515 %! rand ("state", 12);
516 %! x = rand (100000, 1); 516 %! x = rand (100000, 1);
517 %! assert (max (x) < 1); #*** Please report this!!! *** 517 %! assert (max (x) < 1); #*** Please report this!!! ***
518 %! assert (min (x) > 0); #*** Please report this!!! *** 518 %! assert (min (x) > 0); #*** Please report this!!! ***
519 %! assert (mean (x), 0.5, 0.0024); 519 %! assert (mean (x), 0.5, 0.0024);
521 %! assert (skewness (x), 0, 0.012); 521 %! assert (skewness (x), 0, 0.012);
522 %! assert (kurtosis (x), -6/5, 0.0094); 522 %! assert (kurtosis (x), -6/5, 0.0094);
523 %! endif 523 %! endif
524 %!test 524 %!test
525 %! if (__random_statistical_tests__) 525 %! if (__random_statistical_tests__)
526 %! # statistical tests may fail occasionally. 526 %! ## statistical tests may fail occasionally.
527 %! rand ("seed", 12); 527 %! rand ("seed", 12);
528 %! x = rand (100000, 1); 528 %! x = rand (100000, 1);
529 %! assert (max (x) < 1); #*** Please report this!!! *** 529 %! assert (max (x) < 1); #*** Please report this!!! ***
530 %! assert (min (x) > 0); #*** Please report this!!! *** 530 %! assert (min (x) > 0); #*** Please report this!!! ***
531 %! assert (mean (x), 0.5, 0.0024); 531 %! assert (mean (x), 0.5, 0.0024);
591 return retval; 591 return retval;
592 } 592 }
593 593
594 /* 594 /*
595 %!test 595 %!test
596 %! # Test fixed state 596 %! ## Test fixed state
597 %! randn ("state", 1); 597 %! randn ("state", 1);
598 %! assert (randn (1, 6), [-2.666521678978671 -0.7381719971724564 1.507903992673601 0.6019427189162239 -0.450661261143348 -0.7054431351574116], 1e-6); 598 %! assert (randn (1, 6), [-2.666521678978671 -0.7381719971724564 1.507903992673601 0.6019427189162239 -0.450661261143348 -0.7054431351574116], 1e-6);
599 %!test 599 %!test
600 %! # Test fixed seed 600 %! ## Test fixed seed
601 %! randn ("seed", 1); 601 %! randn ("seed", 1);
602 %! assert (randn (1, 6), [-1.039402365684509 -1.25938892364502 0.1968704611063004 0.3874166905879974 -0.5976632833480835 -0.6615074276924133], 1e-6); 602 %! assert (randn (1, 6), [-1.039402365684509 -1.25938892364502 0.1968704611063004 0.3874166905879974 -0.5976632833480835 -0.6615074276924133], 1e-6);
603 %!test 603 %!test
604 %! if (__random_statistical_tests__) 604 %! if (__random_statistical_tests__)
605 %! # statistical tests may fail occasionally. 605 %! ## statistical tests may fail occasionally.
606 %! randn ("state", 12); 606 %! randn ("state", 12);
607 %! x = randn (100000, 1); 607 %! x = randn (100000, 1);
608 %! assert (mean (x), 0, 0.01); 608 %! assert (mean (x), 0, 0.01);
609 %! assert (var (x), 1, 0.02); 609 %! assert (var (x), 1, 0.02);
610 %! assert (skewness (x), 0, 0.02); 610 %! assert (skewness (x), 0, 0.02);
611 %! assert (kurtosis (x), 0, 0.04); 611 %! assert (kurtosis (x), 0, 0.04);
612 %! endif 612 %! endif
613 %!test 613 %!test
614 %! if (__random_statistical_tests__) 614 %! if (__random_statistical_tests__)
615 %! # statistical tests may fail occasionally. 615 %! ## statistical tests may fail occasionally.
616 %! randn ("seed", 12); 616 %! randn ("seed", 12);
617 %! x = randn (100000, 1); 617 %! x = randn (100000, 1);
618 %! assert (mean (x), 0, 0.01); 618 %! assert (mean (x), 0, 0.01);
619 %! assert (var (x), 1, 0.02); 619 %! assert (var (x), 1, 0.02);
620 %! assert (skewness (x), 0, 0.02); 620 %! assert (skewness (x), 0, 0.02);
662 return retval; 662 return retval;
663 } 663 }
664 664
665 /* 665 /*
666 %!test 666 %!test
667 %! # Test fixed state 667 %! ## Test fixed state
668 %! rande ("state", 1); 668 %! rande ("state", 1);
669 %! assert (rande (1, 6), [3.602973885835625 0.1386190677555021 0.6743112889616958 0.4512830847258422 0.7255744741233175 0.3415969205292291], 1e-6); 669 %! assert (rande (1, 6), [3.602973885835625 0.1386190677555021 0.6743112889616958 0.4512830847258422 0.7255744741233175 0.3415969205292291], 1e-6);
670 %!test 670 %!test
671 %! # Test fixed seed 671 %! ## Test fixed seed
672 %! rande ("seed", 1); 672 %! rande ("seed", 1);
673 %! assert (rande (1, 6), [0.06492075175653866 1.717980206012726 0.4816154008731246 0.5231300676241517 0.103910739364359 1.668931916356087], 1e-6); 673 %! assert (rande (1, 6), [0.06492075175653866 1.717980206012726 0.4816154008731246 0.5231300676241517 0.103910739364359 1.668931916356087], 1e-6);
674 %!test 674 %!test
675 %! if (__random_statistical_tests__) 675 %! if (__random_statistical_tests__)
676 %! # statistical tests may fail occasionally 676 %! ## statistical tests may fail occasionally
677 %! rande ("state", 1); 677 %! rande ("state", 1);
678 %! x = rande (100000, 1); 678 %! x = rande (100000, 1);
679 %! assert (min (x) > 0); # *** Please report this!!! *** 679 %! assert (min (x) > 0); # *** Please report this!!! ***
680 %! assert (mean (x), 1, 0.01); 680 %! assert (mean (x), 1, 0.01);
681 %! assert (var (x), 1, 0.03); 681 %! assert (var (x), 1, 0.03);
682 %! assert (skewness (x), 2, 0.06); 682 %! assert (skewness (x), 2, 0.06);
683 %! assert (kurtosis (x), 6, 0.7); 683 %! assert (kurtosis (x), 6, 0.7);
684 %! endif 684 %! endif
685 %!test 685 %!test
686 %! if (__random_statistical_tests__) 686 %! if (__random_statistical_tests__)
687 %! # statistical tests may fail occasionally 687 %! ## statistical tests may fail occasionally
688 %! rande ("seed", 1); 688 %! rande ("seed", 1);
689 %! x = rande (100000, 1); 689 %! x = rande (100000, 1);
690 %! assert (min (x)>0); # *** Please report this!!! *** 690 %! assert (min (x)>0); # *** Please report this!!! ***
691 %! assert (mean (x), 1, 0.01); 691 %! assert (mean (x), 1, 0.01);
692 %! assert (var (x), 1, 0.03); 692 %! assert (var (x), 1, 0.03);
810 %!test 810 %!test
811 %! randg ("state", 12) 811 %! randg ("state", 12)
812 %! assert (randg ([-inf, -1, 0, inf, nan]), [nan, nan, nan, nan, nan]); # *** Please report 812 %! assert (randg ([-inf, -1, 0, inf, nan]), [nan, nan, nan, nan, nan]); # *** Please report
813 813
814 %!test 814 %!test
815 %! # Test fixed state 815 %! ## Test fixed state
816 %! randg ("state", 1); 816 %! randg ("state", 1);
817 %! assert (randg (0.1, 1, 6), [0.0103951513331241 8.335671459898252e-05 0.00138691397249762 0.000587308416993855 0.495590518784736 2.3921917414795e-12], 1e-6); 817 %! assert (randg (0.1, 1, 6), [0.0103951513331241 8.335671459898252e-05 0.00138691397249762 0.000587308416993855 0.495590518784736 2.3921917414795e-12], 1e-6);
818 %!test 818 %!test
819 %! # Test fixed state 819 %! ## Test fixed state
820 %! randg ("state", 1); 820 %! randg ("state", 1);
821 %! assert (randg (0.95, 1, 6), [3.099382433255327 0.3974529788871218 0.644367450750855 1.143261091802246 1.964111762696822 0.04011915547957939], 1e-6); 821 %! assert (randg (0.95, 1, 6), [3.099382433255327 0.3974529788871218 0.644367450750855 1.143261091802246 1.964111762696822 0.04011915547957939], 1e-6);
822 %!test 822 %!test
823 %! # Test fixed state 823 %! ## Test fixed state
824 %! randg ("state", 1); 824 %! randg ("state", 1);
825 %! assert (randg (1, 1, 6), [0.2273389379645993 1.288822625058359 0.2406335209340746 1.218869553370733 1.024649860162554 0.09631230343599533], 1e-6); 825 %! assert (randg (1, 1, 6), [0.2273389379645993 1.288822625058359 0.2406335209340746 1.218869553370733 1.024649860162554 0.09631230343599533], 1e-6);
826 %!test 826 %!test
827 %! # Test fixed state 827 %! ## Test fixed state
828 %! randg ("state", 1); 828 %! randg ("state", 1);
829 %! assert (randg (10, 1, 6), [3.520369644331133 15.15369864472106 8.332112081991205 8.406211067432674 11.81193475187611 10.88792728177059], 1e-5); 829 %! assert (randg (10, 1, 6), [3.520369644331133 15.15369864472106 8.332112081991205 8.406211067432674 11.81193475187611 10.88792728177059], 1e-5);
830 %!test 830 %!test
831 %! # Test fixed state 831 %! ## Test fixed state
832 %! randg ("state", 1); 832 %! randg ("state", 1);
833 %! assert (randg (100, 1, 6), [75.34570255262264 115.4911985594699 95.23493031356388 95.48926019250911 106.2397448229803 103.4813150404118], 1e-4); 833 %! assert (randg (100, 1, 6), [75.34570255262264 115.4911985594699 95.23493031356388 95.48926019250911 106.2397448229803 103.4813150404118], 1e-4);
834 %!test 834 %!test
835 %! # Test fixed seed 835 %! ## Test fixed seed
836 %! randg ("seed", 1); 836 %! randg ("seed", 1);
837 %! assert (randg (0.1, 1, 6), [0.07144210487604141 0.460641473531723 0.4749028384685516 0.06823389977216721 0.000293838675133884 1.802567535340305e-12], 1e-6); 837 %! assert (randg (0.1, 1, 6), [0.07144210487604141 0.460641473531723 0.4749028384685516 0.06823389977216721 0.000293838675133884 1.802567535340305e-12], 1e-6);
838 %!test 838 %!test
839 %! # Test fixed seed 839 %! ## Test fixed seed
840 %! randg ("seed", 1); 840 %! randg ("seed", 1);
841 %! assert (randg (0.95, 1, 6), [1.664905071258545 1.879976987838745 1.905677795410156 0.9948706030845642 0.5606933236122131 0.0766092911362648], 1e-6); 841 %! assert (randg (0.95, 1, 6), [1.664905071258545 1.879976987838745 1.905677795410156 0.9948706030845642 0.5606933236122131 0.0766092911362648], 1e-6);
842 %!test 842 %!test
843 %! # Test fixed seed 843 %! ## Test fixed seed
844 %! randg ("seed", 1); 844 %! randg ("seed", 1);
845 %! assert (randg (1, 1, 6), [0.03512085229158401 0.6488978862762451 0.8114678859710693 0.1666885763406754 1.60791552066803 1.90356981754303], 1e-6); 845 %! assert (randg (1, 1, 6), [0.03512085229158401 0.6488978862762451 0.8114678859710693 0.1666885763406754 1.60791552066803 1.90356981754303], 1e-6);
846 %!test 846 %!test
847 %! # Test fixed seed 847 %! ## Test fixed seed
848 %! randg ("seed", 1); 848 %! randg ("seed", 1);
849 %! assert (randg (10, 1, 6), [6.566435813903809 10.11648464202881 10.73162078857422 7.747178077697754 6.278522491455078 6.240195751190186], 1e-5); 849 %! assert (randg (10, 1, 6), [6.566435813903809 10.11648464202881 10.73162078857422 7.747178077697754 6.278522491455078 6.240195751190186], 1e-5);
850 %!test 850 %!test
851 %! # Test fixed seed 851 %! ## Test fixed seed
852 %! randg ("seed", 1); 852 %! randg ("seed", 1);
853 %! assert (randg (100, 1, 6), [89.40208435058594 101.4734725952148 103.4020004272461 93.62763214111328 88.33104705810547 88.1871337890625], 1e-4); 853 %! assert (randg (100, 1, 6), [89.40208435058594 101.4734725952148 103.4020004272461 93.62763214111328 88.33104705810547 88.1871337890625], 1e-4);
854 854
855 %!test 855 %!test
856 %! if (__random_statistical_tests__) 856 %! if (__random_statistical_tests__)
857 %! # statistical tests may fail occasionally. 857 %! ## statistical tests may fail occasionally.
858 %! randg ("state", 12); 858 %! randg ("state", 12);
859 %! a = 0.1; 859 %! a = 0.1;
860 %! x = randg (a, 100000, 1); 860 %! x = randg (a, 100000, 1);
861 %! assert (mean (x), a, 0.01); 861 %! assert (mean (x), a, 0.01);
862 %! assert (var (x), a, 0.01); 862 %! assert (var (x), a, 0.01);
863 %! assert (skewness (x), 2/sqrt (a), 1); 863 %! assert (skewness (x), 2/sqrt (a), 1);
864 %! assert (kurtosis (x), 6/a, 50); 864 %! assert (kurtosis (x), 6/a, 50);
865 %! endif 865 %! endif
866 %!test 866 %!test
867 %! if (__random_statistical_tests__) 867 %! if (__random_statistical_tests__)
868 %! # statistical tests may fail occasionally. 868 %! ## statistical tests may fail occasionally.
869 %! randg ("state", 12); 869 %! randg ("state", 12);
870 %! a = 0.95; 870 %! a = 0.95;
871 %! x = randg (a, 100000, 1); 871 %! x = randg (a, 100000, 1);
872 %! assert (mean (x), a, 0.01); 872 %! assert (mean (x), a, 0.01);
873 %! assert (var (x), a, 0.04); 873 %! assert (var (x), a, 0.04);
874 %! assert (skewness (x), 2/sqrt (a), 0.2); 874 %! assert (skewness (x), 2/sqrt (a), 0.2);
875 %! assert (kurtosis (x), 6/a, 2); 875 %! assert (kurtosis (x), 6/a, 2);
876 %! endif 876 %! endif
877 %!test 877 %!test
878 %! if (__random_statistical_tests__) 878 %! if (__random_statistical_tests__)
879 %! # statistical tests may fail occasionally. 879 %! ## statistical tests may fail occasionally.
880 %! randg ("state", 12); 880 %! randg ("state", 12);
881 %! a = 1; 881 %! a = 1;
882 %! x = randg (a, 100000, 1); 882 %! x = randg (a, 100000, 1);
883 %! assert (mean (x), a, 0.01); 883 %! assert (mean (x), a, 0.01);
884 %! assert (var (x), a, 0.04); 884 %! assert (var (x), a, 0.04);
885 %! assert (skewness (x), 2/sqrt (a), 0.2); 885 %! assert (skewness (x), 2/sqrt (a), 0.2);
886 %! assert (kurtosis (x), 6/a, 2); 886 %! assert (kurtosis (x), 6/a, 2);
887 %! endif 887 %! endif
888 %!test 888 %!test
889 %! if (__random_statistical_tests__) 889 %! if (__random_statistical_tests__)
890 %! # statistical tests may fail occasionally. 890 %! ## statistical tests may fail occasionally.
891 %! randg ("state", 12); 891 %! randg ("state", 12);
892 %! a = 10; 892 %! a = 10;
893 %! x = randg (a, 100000, 1); 893 %! x = randg (a, 100000, 1);
894 %! assert (mean (x), a, 0.1); 894 %! assert (mean (x), a, 0.1);
895 %! assert (var (x), a, 0.5); 895 %! assert (var (x), a, 0.5);
896 %! assert (skewness (x), 2/sqrt (a), 0.1); 896 %! assert (skewness (x), 2/sqrt (a), 0.1);
897 %! assert (kurtosis (x), 6/a, 0.5); 897 %! assert (kurtosis (x), 6/a, 0.5);
898 %! endif 898 %! endif
899 %!test 899 %!test
900 %! if (__random_statistical_tests__) 900 %! if (__random_statistical_tests__)
901 %! # statistical tests may fail occasionally. 901 %! ## statistical tests may fail occasionally.
902 %! randg ("state", 12); 902 %! randg ("state", 12);
903 %! a = 100; 903 %! a = 100;
904 %! x = randg (a, 100000, 1); 904 %! x = randg (a, 100000, 1);
905 %! assert (mean (x), a, 0.2); 905 %! assert (mean (x), a, 0.2);
906 %! assert (var (x), a, 2); 906 %! assert (var (x), a, 2);
910 %!test 910 %!test
911 %! randg ("seed", 12); 911 %! randg ("seed", 12);
912 %!assert (randg ([-inf, -1, 0, inf, nan]), [nan, nan, nan, nan, nan]) # *** Please report 912 %!assert (randg ([-inf, -1, 0, inf, nan]), [nan, nan, nan, nan, nan]) # *** Please report
913 %!test 913 %!test
914 %! if (__random_statistical_tests__) 914 %! if (__random_statistical_tests__)
915 %! # statistical tests may fail occasionally. 915 %! ## statistical tests may fail occasionally.
916 %! randg ("seed", 12); 916 %! randg ("seed", 12);
917 %! a = 0.1; 917 %! a = 0.1;
918 %! x = randg (a, 100000, 1); 918 %! x = randg (a, 100000, 1);
919 %! assert (mean (x), a, 0.01); 919 %! assert (mean (x), a, 0.01);
920 %! assert (var (x), a, 0.01); 920 %! assert (var (x), a, 0.01);
921 %! assert (skewness (x), 2/sqrt (a), 1); 921 %! assert (skewness (x), 2/sqrt (a), 1);
922 %! assert (kurtosis (x), 6/a, 50); 922 %! assert (kurtosis (x), 6/a, 50);
923 %! endif 923 %! endif
924 %!test 924 %!test
925 %! if (__random_statistical_tests__) 925 %! if (__random_statistical_tests__)
926 %! # statistical tests may fail occasionally. 926 %! ## statistical tests may fail occasionally.
927 %! randg ("seed", 12); 927 %! randg ("seed", 12);
928 %! a = 0.95; 928 %! a = 0.95;
929 %! x = randg (a, 100000, 1); 929 %! x = randg (a, 100000, 1);
930 %! assert (mean (x), a, 0.01); 930 %! assert (mean (x), a, 0.01);
931 %! assert (var (x), a, 0.04); 931 %! assert (var (x), a, 0.04);
932 %! assert (skewness (x), 2/sqrt (a), 0.2); 932 %! assert (skewness (x), 2/sqrt (a), 0.2);
933 %! assert (kurtosis (x), 6/a, 2); 933 %! assert (kurtosis (x), 6/a, 2);
934 %! endif 934 %! endif
935 %!test 935 %!test
936 %! if (__random_statistical_tests__) 936 %! if (__random_statistical_tests__)
937 %! # statistical tests may fail occasionally. 937 %! ## statistical tests may fail occasionally.
938 %! randg ("seed", 12); 938 %! randg ("seed", 12);
939 %! a = 1; 939 %! a = 1;
940 %! x = randg (a, 100000, 1); 940 %! x = randg (a, 100000, 1);
941 %! assert (mean (x), a, 0.01); 941 %! assert (mean (x), a, 0.01);
942 %! assert (var (x), a, 0.04); 942 %! assert (var (x), a, 0.04);
943 %! assert (skewness (x), 2/sqrt (a), 0.2); 943 %! assert (skewness (x), 2/sqrt (a), 0.2);
944 %! assert (kurtosis (x), 6/a, 2); 944 %! assert (kurtosis (x), 6/a, 2);
945 %! endif 945 %! endif
946 %!test 946 %!test
947 %! if (__random_statistical_tests__) 947 %! if (__random_statistical_tests__)
948 %! # statistical tests may fail occasionally. 948 %! ## statistical tests may fail occasionally.
949 %! randg ("seed", 12); 949 %! randg ("seed", 12);
950 %! a = 10; 950 %! a = 10;
951 %! x = randg (a, 100000, 1); 951 %! x = randg (a, 100000, 1);
952 %! assert (mean (x), a, 0.1); 952 %! assert (mean (x), a, 0.1);
953 %! assert (var (x), a, 0.5); 953 %! assert (var (x), a, 0.5);
954 %! assert (skewness (x), 2/sqrt (a), 0.1); 954 %! assert (skewness (x), 2/sqrt (a), 0.1);
955 %! assert (kurtosis (x), 6/a, 0.5); 955 %! assert (kurtosis (x), 6/a, 0.5);
956 %! endif 956 %! endif
957 %!test 957 %!test
958 %! if (__random_statistical_tests__) 958 %! if (__random_statistical_tests__)
959 %! # statistical tests may fail occasionally. 959 %! ## statistical tests may fail occasionally.
960 %! randg ("seed", 12); 960 %! randg ("seed", 12);
961 %! a = 100; 961 %! a = 100;
962 %! x = randg (a, 100000, 1); 962 %! x = randg (a, 100000, 1);
963 %! assert (mean (x), a, 0.2); 963 %! assert (mean (x), a, 0.2);
964 %! assert (var (x), a, 2); 964 %! assert (var (x), a, 2);
1032 /* 1032 /*
1033 %!test 1033 %!test
1034 %! randp ("state", 12); 1034 %! randp ("state", 12);
1035 %! assert (randp ([-inf, -1, 0, inf, nan]), [nan, nan, 0, nan, nan]); # *** Please report 1035 %! assert (randp ([-inf, -1, 0, inf, nan]), [nan, nan, 0, nan, nan]); # *** Please report
1036 %!test 1036 %!test
1037 %! # Test fixed state 1037 %! ## Test fixed state
1038 %! randp ("state", 1); 1038 %! randp ("state", 1);
1039 %! assert (randp (5, 1, 6), [5 5 3 7 7 3]) 1039 %! assert (randp (5, 1, 6), [5 5 3 7 7 3])
1040 %!test 1040 %!test
1041 %! # Test fixed state 1041 %! ## Test fixed state
1042 %! randp ("state", 1); 1042 %! randp ("state", 1);
1043 %! assert (randp (15, 1, 6), [13 15 8 18 18 15]) 1043 %! assert (randp (15, 1, 6), [13 15 8 18 18 15])
1044 %!test 1044 %!test
1045 %! # Test fixed state 1045 %! ## Test fixed state
1046 %! randp ("state", 1); 1046 %! randp ("state", 1);
1047 %! assert (randp (1e9, 1, 6), [999915677 999976657 1000047684 1000019035 999985749 999977692], -1e-6) 1047 %! assert (randp (1e9, 1, 6), [999915677 999976657 1000047684 1000019035 999985749 999977692], -1e-6)
1048 %!test 1048 %!test
1049 %! # Test fixed state 1049 %! ## Test fixed state
1050 %! randp ("seed", 1); 1050 %! randp ("seed", 1);
1051 %! %%assert (randp (5, 1, 6), [8 2 3 6 6 8]) 1051 %! %%assert (randp (5, 1, 6), [8 2 3 6 6 8])
1052 %! assert (randp (5, 1, 5), [8 2 3 6 6]) 1052 %! assert (randp (5, 1, 5), [8 2 3 6 6])
1053 %!test 1053 %!test
1054 %! # Test fixed state 1054 %! ## Test fixed state
1055 %! randp ("seed", 1); 1055 %! randp ("seed", 1);
1056 %! assert (randp (15, 1, 6), [15 16 12 10 10 12]) 1056 %! assert (randp (15, 1, 6), [15 16 12 10 10 12])
1057 %!test 1057 %!test
1058 %! # Test fixed state 1058 %! ## Test fixed state
1059 %! randp ("seed", 1); 1059 %! randp ("seed", 1);
1060 %! assert (randp (1e9, 1, 6), [1000006208 1000012224 999981120 999963520 999963072 999981440], -1e-6) 1060 %! assert (randp (1e9, 1, 6), [1000006208 1000012224 999981120 999963520 999963072 999981440], -1e-6)
1061 %!test 1061 %!test
1062 %! if (__random_statistical_tests__) 1062 %! if (__random_statistical_tests__)
1063 %! # statistical tests may fail occasionally. 1063 %! ## statistical tests may fail occasionally.
1064 %! randp ("state", 12); 1064 %! randp ("state", 12);
1065 %! for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03] 1065 %! for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
1066 %! x = randp (a (1), 100000, 1); 1066 %! x = randp (a (1), 100000, 1);
1067 %! assert (min (x) >= 0); # *** Please report this!!! *** 1067 %! assert (min (x) >= 0); # *** Please report this!!! ***
1068 %! assert (mean (x), a(1), a(2)); 1068 %! assert (mean (x), a(1), a(2));
1071 %! assert (kurtosis (x), 1/a(1), 3*a(3)); 1071 %! assert (kurtosis (x), 1/a(1), 3*a(3));
1072 %! endfor 1072 %! endfor
1073 %! endif 1073 %! endif
1074 %!test 1074 %!test
1075 %! if (__random_statistical_tests__) 1075 %! if (__random_statistical_tests__)
1076 %! # statistical tests may fail occasionally. 1076 %! ## statistical tests may fail occasionally.
1077 %! randp ("state", 12); 1077 %! randp ("state", 12);
1078 %! for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03] 1078 %! for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
1079 %! x = randp (a(1)*ones (100000, 1), 100000, 1); 1079 %! x = randp (a(1)*ones (100000, 1), 100000, 1);
1080 %! assert (min (x) >= 0); # *** Please report this!!! *** 1080 %! assert (min (x) >= 0); # *** Please report this!!! ***
1081 %! assert (mean (x), a(1), a(2)); 1081 %! assert (mean (x), a(1), a(2));
1087 %!test 1087 %!test
1088 %! randp ("seed", 12); 1088 %! randp ("seed", 12);
1089 %! assert (randp ([-inf, -1, 0, inf, nan]), [nan, nan, 0, nan, nan]); # *** Please report 1089 %! assert (randp ([-inf, -1, 0, inf, nan]), [nan, nan, 0, nan, nan]); # *** Please report
1090 %!test 1090 %!test
1091 %! if (__random_statistical_tests__) 1091 %! if (__random_statistical_tests__)
1092 %! # statistical tests may fail occasionally. 1092 %! ## statistical tests may fail occasionally.
1093 %! randp ("seed", 12); 1093 %! randp ("seed", 12);
1094 %! for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03] 1094 %! for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
1095 %! x = randp (a(1), 100000, 1); 1095 %! x = randp (a(1), 100000, 1);
1096 %! assert (min (x) >= 0); # *** Please report this!!! *** 1096 %! assert (min (x) >= 0); # *** Please report this!!! ***
1097 %! assert (mean (x), a(1), a(2)); 1097 %! assert (mean (x), a(1), a(2));
1100 %! assert (kurtosis (x), 1/a(1), 3*a(3)); 1100 %! assert (kurtosis (x), 1/a(1), 3*a(3));
1101 %! endfor 1101 %! endfor
1102 %! endif 1102 %! endif
1103 %!test 1103 %!test
1104 %! if (__random_statistical_tests__) 1104 %! if (__random_statistical_tests__)
1105 %! # statistical tests may fail occasionally. 1105 %! ## statistical tests may fail occasionally.
1106 %! randp ("seed", 12); 1106 %! randp ("seed", 12);
1107 %! for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03] 1107 %! for a = [5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03]
1108 %! x = randp (a(1)*ones (100000, 1), 100000, 1); 1108 %! x = randp (a(1)*ones (100000, 1), 100000, 1);
1109 %! assert (min (x) >= 0); # *** Please report this!!! *** 1109 %! assert (min (x) >= 0); # *** Please report this!!! ***
1110 %! assert (mean (x), a(1), a(2)); 1110 %! assert (mean (x), a(1), a(2));