aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2009-04-03 08:21:49 +0000
committerRichard Guenther <rguenther@suse.de>2009-04-03 08:21:49 +0000
commitec0e1004b31f6bf31b1afd325230505352fa4b8d (patch)
tree40fd6ac96cd9cdaead2cd90b4680c42219611a8c
parent40f4218ef050663050dcd7183e2db36ce7bb0e05 (diff)
2009-04-03 Richard Guenther <rguenther@suse.de>
Merge from trunk r145490. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/alias-improvements@145491 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog141
-rw-r--r--gcc/ChangeLog.alias4
-rw-r--r--gcc/DATESTAMP2
-rw-r--r--gcc/builtins.c22
-rw-r--r--gcc/c-decl.c10
-rw-r--r--gcc/cgraph.h1
-rw-r--r--gcc/config.gcc36
-rw-r--r--gcc/config/i386/i386.c4
-rw-r--r--gcc/config/mips/mips-protos.h2
-rw-r--r--gcc/config/mips/mips.c533
-rw-r--r--gcc/config/mips/mips.h40
-rw-r--r--gcc/config/mips/mips.md60
-rw-r--r--gcc/config/mips/sde.h3
-rw-r--r--gcc/config/rs6000/linux64.h6
-rw-r--r--gcc/config/rs6000/sysv4.h1
-rw-r--r--gcc/config/rs6000/sysv4.opt2
-rw-r--r--gcc/config/rs6000/t-linux643
-rw-r--r--gcc/config/sh/linux-unwind.h9
-rw-r--r--gcc/config/sh/sh-protos.h3
-rw-r--r--gcc/config/sh/sh.c25
-rwxr-xr-xgcc/configure2
-rw-r--r--gcc/configure.ac2
-rw-r--r--gcc/cp/ChangeLog9
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/cp/error.c67
-rw-r--r--gcc/cp/pt.c3
-rw-r--r--gcc/doc/extend.texi38
-rw-r--r--gcc/doc/invoke.texi36
-rw-r--r--gcc/gcc.c125
-rw-r--r--gcc/passes.c2
-rw-r--r--gcc/reload1.c15
-rw-r--r--gcc/testsuite/ChangeLog25
-rw-r--r--gcc/testsuite/g++.dg/template/error38.C19
-rw-r--r--gcc/testsuite/gcc.dg/memcpy-1.c2
-rw-r--r--gcc/testsuite/gcc.target/mips/interrupt_handler.c23
-rw-r--r--gcc/testsuite/gfortran.dg/vect/O3-pr39595.f17
-rw-r--r--gcc/testsuite/objc.dg/bad-receiver-type-2.m41
-rw-r--r--gcc/tree-vect-slp.c16
-rw-r--r--gcc/tree.h1
-rw-r--r--gcc/varasm.c2
-rw-r--r--gcc/varpool.c8
-rw-r--r--libgcc/ChangeLog4
-rw-r--r--libgcc/config.host6
-rw-r--r--libstdc++-v3/ChangeLog320
-rw-r--r--libstdc++-v3/include/Makefile.am6
-rw-r--r--libstdc++-v3/include/Makefile.in6
-rw-r--r--libstdc++-v3/include/bits/random.h4940
-rw-r--r--libstdc++-v3/include/bits/random.tcc2794
-rw-r--r--libstdc++-v3/include/std/random16
-rw-r--r--libstdc++-v3/include/tr1/random8
-rw-r--r--libstdc++-v3/include/tr1/random.h2436
-rw-r--r--libstdc++-v3/include/tr1/random.tcc1583
-rw-r--r--libstdc++-v3/include/tr1_impl/random2412
-rw-r--r--libstdc++-v3/include/tr1_impl/random.tcc1582
-rw-r--r--libstdc++-v3/testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc17
-rw-r--r--libstdc++-v3/testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc19
-rw-r--r--libstdc++-v3/testsuite/26_numerics/headers/random/std_c++0x_neg.cc2
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/default.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/parms.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/default.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/parms.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/default.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/parms.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/default.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/parms.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/default_random_engine.cc48
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_copy.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_move.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/default.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed1.cc47
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed2.cc47
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed_seq.cc47
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/equal.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc55
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/requirements/typedefs.cc39
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/default.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/initlist.cc43
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/num_xbound_fun.cc67
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/range.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/operators/serialize.cc53
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/default.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/parms.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/default.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/parms.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/default.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/parms.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/default.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/parms.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/default.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/parms.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_copy.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_move.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/default.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed1.cc48
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed2.cc48
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed_seq.cc48
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/equal.cc50
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc53
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/requirements/typedefs.cc42
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/knuth_b.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/default.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed1.cc40
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed2.cc40
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/equal.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc51
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/non_uint_neg.cc33
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/default.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/parms.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/default.cc51
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed1.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed2.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/equal.cc53
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc56
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/requirements/typedefs.cc40
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/minstd_rand.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/minstd_rand0.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/mt19937.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/mt19937_64.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/default.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/parms.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/default.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/parms.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/normal_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/default.cc48
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/initlist_fun.cc71
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/num_xbound_fun.cc69
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/range.cc51
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/operators/serialize.cc55
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/default.cc49
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/initlist_fun.cc71
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/num_xbound_fun.cc69
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/range.cc51
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/operators/serialize.cc55
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/default.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/parms.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/random_device/cons/default.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/random_device/cons/token.cc48
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/random_device/requirements/typedefs.cc34
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/ranlux24.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/ranlux24_base.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/ranlux48.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/ranlux48_base.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/default.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/initlist.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/range.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/seed_seq/requirements/typedefs.cc34
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_copy.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_move.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/default.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed1.cc47
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed2.cc47
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq.cc47
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/equal.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc55
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/requirements/typedefs.cc41
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/default.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/parms.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/default.cc44
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed1.cc40
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed2.cc40
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/equal.cc49
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/requirements/typedefs.cc36
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms_neg.cc41
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/default.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms.cc45
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms_neg.cc41
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/requirements/typedefs.cc35
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/default.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/parms.cc46
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/operators/serialize.cc52
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/requirements/typedefs.cc35
208 files changed, 20234 insertions, 4184 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e50c34ceb08..7c7b7cf5745 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,144 @@
+2009-04-03 Alan Modra <amodra@bigpond.net.au>
+
+ * config.gcc (powerpc-*-linux*): Merge variants.
+
+2009-04-02 Chao-ying Fu <fu@mips.com>
+ James Grosbach <james.grosbach@microchip.com>
+
+ * config/mips/mips.c (mips_frame_info): Add acc_mask, num_acc,
+ num_cop0_regs, acc_save_offset, cop0_save_offset, acc_sp_offset,
+ cop0_sp_offset.
+ (machine_function): Add interrupt_handler_p, use_shadow_register_set_p,
+ keep_interrupts_masked_p, use_debug_exception_return_p.
+ (mips_attribute_table): Add interrupt, use_shadow_register_set,
+ keep_interrupts_masked, use_debug_exception_return.
+ (mips_interrupt_type_p, mips_use_shadow_register_set_p,
+ mips_keep_interrupts_masked_p, mips_use_debug_exception_return_p):
+ New functions.
+ (mips_function_ok_for_sibcall): Return false for interrupt handlers.
+ (mips_print_operand): Process COP0 registers to print $0 .. $31
+ correctly for GAS to process.
+ (mips_interrupt_extra_call_saved_reg_p): New function.
+ (mips_cfun_call_saved_reg_p): For interrupt handlers, we need to check
+ extra registers.
+ (mips_cfun_might_clobber_call_saved_reg_p): Likewise.
+ (mips_compute_frame_info): Add supports for interrupt context that
+ includes doubleword accumulators and COP0 registers.
+ (mips_for_each_saved_acc): New function.
+ (mips_for_each_saved_gpr_and_fpr): Change the function name from
+ mips_for_each_saved_reg.
+ (mips_save_reg): Save accumulators.
+ (mips_kernel_reg_p): A new for_each_rtx callback.
+ (mips_expand_prologue): Support interrupt handlers.
+ (mips_restore_reg): Restore accumulators.
+ (mips_expand_epilogue): Support interrupt handlers.
+ (mips_can_use_return_insn): Return false for interrupt handlers.
+ (mips_epilogue_uses): New function.
+ * config/mips/mips.md (UNSPEC_ERET, UNSPEC_DERET, UNSPEC_DI,
+ UNSPEC_EHB, UNSPEC_RDPGPR, UNSPEC_COP0): New UNSPEC.
+ (mips_eret, mips_deret, mips_di, mips_ehb, mips_rdpgpr,
+ cop0_move): New instructions.
+ * config/mips/mips-protos.h (mips_epilogue_uses): Declare.
+ * config/mips/mips.h (K0_REG_NUM, K1_REG_NUM, KERNEL_REG_P): New
+ defines.
+ (COP0_STATUS_REG_NUM, COP0_CAUSE_REG_NUM, COP0_EPC_REG_NUM):
+ New defines.
+ (CAUSE_IPL, SR_IPL, SR_EXL, SR_IE): New defines.
+ (MIPS_PROLOGUE_TEMP_REGNUM, MIPS_EPILOGUE_TEMP_REGNUM): For
+ interrupt handlers, we use K0 as the temporary register.
+ (EPILOGUE_USES): Change to a function call.
+ * config/mips/sde.h (MIPS_EPILOGUE_TEMP_REGNUM): For interrupt
+ handlers, we use K0 as the temporary register.
+
+ * doc/extend.texi (Function Attributes): Document interrupt,
+ use_shadow_register_set, keep_interrupts_masked,
+ use_debug_exception_return for MIPS attributes.
+
+2009-04-03 Alan Modra <amodra@bigpond.net.au>
+
+ * config.gcc (powerpc64-*-gnu*): Add rs6000/default64.h to tm_file.
+ Remove a number of t-files from tmake_file.
+ * config/rs6000/sysv4.opt (mprototype): Name variable target_prototype.
+ * config/rs6000/sysv4.h (TARGET_PROTOTYPE): Define.
+ * config/rs6000/linux64.h (SUBSUBTARGET_OVERRIDE_OPTIONS): Set
+ target_prototype, not TARGET_PROTOTYPE.
+ (LINK_OS_GNU_SPEC): Define.
+ * config/rs6000/t-linux64 (LIB2FUNCS_EXTRA): Delete tramp.S
+ and darwin-ldoubdle.c.
+
+2009-04-02 Michael Meissner <meissner@linux.vnet.ibm.com>
+
+ PR driver/39293
+ * gcc.c (save_temps_flag): Add support for -save-temps=obj.
+ (cpp_options): Ditto.
+ (default_compilers): Ditto.
+ (display_help): Ditto.
+ (process_command): Ditto.
+ (do_spec_1): Ditto.
+ (set_input): Use lbasename instead of duplicate code.
+ (save_temps_prefix): New static for -save-temps=obj.
+ (save_temps_length): Ditto.
+
+ * doc/invoke.texi (-save-temps=obj): Document new variant to
+ -save-temps switch.
+
+2009-04-02 Jeff Law <law@redhat.com>
+
+ * reload1.c (fixup_eh_region_notes): Remove write-only "trap_count"
+ variable.
+
+2009-04-02 H.J. Lu <hongjiu.lu@intel.com>
+
+ * configure.ac: Support -Bstatic/-Bdynamic for linker version > 2.
+ * configure: Regenerated.
+
+2009-04-02 Rafael Avila de Espindola <espindola@google.com>
+
+ * c-decl.c (merge_decls): Make sure newdecl and olddecl don't
+ share the argument list.
+
+2009-04-02 Rafael Avila de Espindola <espindola@google.com>
+
+ Merge
+
+ 2009-02-12 Diego Novillo <dnovillo@google.com>
+
+ * varpool.c (debug_varpool): New.
+ * cgraph.h (debug_varpool): Declare.
+
+2009-04-02 Jan Hubicka <jh@suse.cz>
+
+ * passes.c (init_optimization_passes): Remove two copies of ehcleanup
+ pass.
+
+2009-04-02 H.J. Lu <hongjiu.lu@intel.com>
+
+ * config/i386/i386.c (ix86_abi): Move initialization to ...
+ (override_options): Here.
+
+2009-04-02 Christian Bruel <christian.bruel@st.com>
+
+ * config/sh/sh.c (sh_dwarf_register_span): New function.
+ (TARGET_DWARF_REGISTER_SPAN): Define.
+ * config/sh/sh-protos.h (sh_dwarf_register_span): Declare.
+
+2009-04-02 Ira Rosen <irar@il.ibm.com>
+
+ PR tree-optimization/39595
+ * tree-vect-slp.c (vect_build_slp_tree): Check that the size of
+ interleaved loads group is not greater than the SLP group size.
+
+2009-04-02 Rafael Avila de Espindola <espindola@google.com>
+
+ * builtins.c (is_builtin_name): New.
+ (called_as_built_in): Use is_builtin_name.
+ * tree.h (is_builtin_name): New.
+ * varasm.c (incorporeal_function_p): Use is_builtin_name
+
+2009-04-02 Andrew Stubbs <ams@codesourcery.com>
+
+ * config/sh/linux-unwind.h: Disable when inhibit_libc is defined.
+
2009-04-02 Dodji Seketeli <dodji@redhat.com>
PR c++/26693
diff --git a/gcc/ChangeLog.alias b/gcc/ChangeLog.alias
index 5a7a0b4c15c..438475dc5fc 100644
--- a/gcc/ChangeLog.alias
+++ b/gcc/ChangeLog.alias
@@ -1,3 +1,7 @@
+2009-04-03 Richard Guenther <rguenther@suse.de>
+
+ Merge from trunk r145490.
+
2009-04-02 Richard Guenther <rguenther@suse.de>
Merge from trunk r145440.
diff --git a/gcc/DATESTAMP b/gcc/DATESTAMP
index 516b726d6c5..74c8ed566e2 100644
--- a/gcc/DATESTAMP
+++ b/gcc/DATESTAMP
@@ -1 +1 @@
-20090402
+20090403
diff --git a/gcc/builtins.c b/gcc/builtins.c
index e22c5f58964..9f0f4ac4fba 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -241,13 +241,9 @@ static tree do_mpfr_bessel_n (tree, tree, tree,
static tree do_mpfr_remquo (tree, tree, tree);
static tree do_mpfr_lgamma_r (tree, tree, tree);
-/* Return true if NODE should be considered for inline expansion regardless
- of the optimization level. This means whenever a function is invoked with
- its "internal" name, which normally contains the prefix "__builtin". */
-
-static bool called_as_built_in (tree node)
+bool
+is_builtin_name (const char *name)
{
- const char *name = IDENTIFIER_POINTER (DECL_NAME (node));
if (strncmp (name, "__builtin_", 10) == 0)
return true;
if (strncmp (name, "__sync_", 7) == 0)
@@ -255,6 +251,20 @@ static bool called_as_built_in (tree node)
return false;
}
+/* Return true if NODE should be considered for inline expansion regardless
+ of the optimization level. This means whenever a function is invoked with
+ its "internal" name, which normally contains the prefix "__builtin". */
+
+static bool
+called_as_built_in (tree node)
+{
+ /* Note that we must use DECL_NAME, not DECL_ASSEMBLER_NAME_SET_P since
+ we want the name used to call the function, not the name it
+ will have. */
+ const char *name = IDENTIFIER_POINTER (DECL_NAME (node));
+ return is_builtin_name (name);
+}
+
/* Return the alignment in bits of EXP, an object.
Don't return more than MAX_ALIGN no matter what, ALIGN is the inital
guessed alignment e.g. from type alignment. */
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 8930d93c0cd..76f7fe482f5 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -1853,12 +1853,15 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
/* Also preserve various other info from the definition. */
if (!new_is_definition)
{
+ tree t;
DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
gimple_set_body (newdecl, gimple_body (olddecl));
- DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
+ DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl));
+ for (t = DECL_ARGUMENTS (newdecl); t ; t = TREE_CHAIN (t))
+ DECL_CONTEXT (t) = newdecl;
/* See if we've got a function to instantiate from. */
if (DECL_SAVED_TREE (olddecl))
@@ -1880,6 +1883,9 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
{
unsigned olddecl_uid = DECL_UID (olddecl);
tree olddecl_context = DECL_CONTEXT (olddecl);
+ tree olddecl_arguments = NULL;
+ if (TREE_CODE (olddecl) == FUNCTION_DECL)
+ olddecl_arguments = DECL_ARGUMENTS (olddecl);
memcpy ((char *) olddecl + sizeof (struct tree_common),
(char *) newdecl + sizeof (struct tree_common),
@@ -1910,6 +1916,8 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
}
DECL_UID (olddecl) = olddecl_uid;
DECL_CONTEXT (olddecl) = olddecl_context;
+ if (TREE_CODE (olddecl) == FUNCTION_DECL)
+ DECL_ARGUMENTS (olddecl) = olddecl_arguments;
}
/* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index 0e01a659419..aba0e5927a3 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -406,6 +406,7 @@ extern GTY(()) struct varpool_node *varpool_nodes;
struct varpool_node *varpool_node (tree);
struct varpool_node *varpool_node_for_asm (tree asmname);
void varpool_mark_needed_node (struct varpool_node *);
+void debug_varpool (void);
void dump_varpool (FILE *);
void dump_varpool_node (FILE *, struct varpool_node *);
diff --git a/gcc/config.gcc b/gcc/config.gcc
index cf8c91b2f12..3eb886fbb45 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1723,9 +1723,9 @@ powerpc64-*-linux*)
tmake_file="t-dfprules rs6000/t-fprules ${tmake_file} rs6000/t-ppccomm rs6000/t-linux64 rs6000/t-fprules-softfp soft-fp/t-softfp"
;;
powerpc64-*-gnu*)
- tm_file="${cpu_type}/${cpu_type}.h elfos.h svr4.h freebsd-spec.h gnu.h rs6000/sysv4.h rs6000/linux64.h rs6000/gnu.h glibc-stdint.h"
+ tm_file="${tm_file} elfos.h svr4.h freebsd-spec.h gnu.h rs6000/sysv4.h rs6000/default64.h rs6000/linux64.h rs6000/gnu.h glibc-stdint.h"
extra_options="${extra_options} rs6000/sysv4.opt rs6000/linux64.opt"
- tmake_file="rs6000/t-fprules t-slibgcc-elf-ver t-gnu rs6000/t-linux64 rs6000/t-fprules-softfp soft-fp/t-softfp"
+ tmake_file="t-slibgcc-elf-ver t-gnu"
;;
powerpc-*-darwin*)
extra_options="${extra_options} rs6000/darwin.opt"
@@ -1805,27 +1805,17 @@ powerpc-*-rtems*)
extra_options="${extra_options} rs6000/sysv4.opt"
tmake_file="rs6000/t-fprules rs6000/t-fprules-fpbit rs6000/t-rtems t-rtems rs6000/t-ppccomm"
;;
-powerpc-*-linux*altivec*)
- tm_file="${tm_file} dbxelf.h elfos.h svr4.h freebsd-spec.h rs6000/sysv4.h rs6000/linux.h rs6000/linuxaltivec.h glibc-stdint.h"
- extra_options="${extra_options} rs6000/sysv4.opt"
- tmake_file="rs6000/t-fprules rs6000/t-fprules-softfp soft-fp/t-softfp rs6000/t-ppcos ${tmake_file} rs6000/t-ppccomm"
- ;;
-powerpc-*-linux*spe*)
- tm_file="${tm_file} dbxelf.h elfos.h svr4.h freebsd-spec.h rs6000/sysv4.h rs6000/linux.h rs6000/linuxspe.h rs6000/e500.h glibc-stdint.h"
- extra_options="${extra_options} rs6000/sysv4.opt"
- tmake_file="t-dfprules rs6000/t-fprules rs6000/t-fprules-softfp soft-fp/t-softfp rs6000/t-ppcos ${tmake_file} rs6000/t-ppccomm"
- ;;
-powerpc-*-linux*paired*)
- tm_file="${tm_file} dbxelf.h elfos.h svr4.h freebsd-spec.h rs6000/sysv4.h rs6000/linux.h rs6000/750cl.h glibc-stdint.h"
- extra_options="${extra_options} rs6000/sysv4.opt"
- tmake_file="rs6000/t-fprules rs6000/t-fprules-softfp soft-fp/t-softfp rs6000/t-ppcos ${tmake_file} rs6000/t-ppccomm"
- ;;
powerpc-*-linux*)
tm_file="${tm_file} dbxelf.h elfos.h svr4.h freebsd-spec.h rs6000/sysv4.h"
extra_options="${extra_options} rs6000/sysv4.opt"
tmake_file="t-dfprules rs6000/t-fprules rs6000/t-fprules-softfp soft-fp/t-softfp rs6000/t-ppcos ${tmake_file} rs6000/t-ppccomm"
- case ${enable_targets}:${cpu_is_64bit} in
- *powerpc64* | all:* | *:yes)
+ maybe_biarch=yes
+ case ${target} in
+ powerpc-*-linux*spe* | powerpc-*-linux*paired*)
+ maybe_biarch= ;;
+ esac
+ case ${maybe_biarch}:${enable_targets}:${cpu_is_64bit} in
+ yes:*powerpc64* | yes:all:* | yes:*:yes)
if test x$cpu_is_64bit = xyes; then
tm_file="${tm_file} rs6000/default64.h"
fi
@@ -1837,6 +1827,14 @@ powerpc-*-linux*)
tm_file="${tm_file} rs6000/linux.h glibc-stdint.h"
;;
esac
+ case ${target} in
+ powerpc*-*-linux*altivec*)
+ tm_file="${tm_file} rs6000/linuxaltivec.h" ;;
+ powerpc*-*-linux*spe*)
+ tm_file="${tm_file} rs6000/linuxspe.h rs6000/e500.h" ;;
+ powerpc*-*-linux*paired*)
+ tm_file="${tm_file} rs6000/750cl.h" ;;
+ esac
if test x${enable_secureplt} = xyes; then
tm_file="rs6000/secureplt.h ${tm_file}"
fi
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 8c89823b535..154c32414f3 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -1744,7 +1744,7 @@ static unsigned int ix86_default_incoming_stack_boundary;
unsigned int ix86_incoming_stack_boundary;
/* The abi used by target. */
-enum calling_abi ix86_abi = DEFAULT_ABI;
+enum calling_abi ix86_abi;
/* Values 1-5: see jump.c */
int ix86_branch_cost;
@@ -2732,6 +2732,8 @@ override_options (bool main_args_p)
error ("unknown ABI (%s) for %sabi=%s %s",
ix86_abi_string, prefix, suffix, sw);
}
+ else
+ ix86_abi = DEFAULT_ABI;
if (ix86_cmodel_string != 0)
{
diff --git a/gcc/config/mips/mips-protos.h b/gcc/config/mips/mips-protos.h
index d00b368d9fa..a704750286b 100644
--- a/gcc/config/mips/mips-protos.h
+++ b/gcc/config/mips/mips-protos.h
@@ -332,4 +332,6 @@ extern void mips_expand_atomic_qihi (union mips_gen_fn_ptrs,
extern void mips_expand_vector_init (rtx, rtx);
+extern bool mips_epilogue_uses (unsigned int);
+
#endif /* ! GCC_MIPS_PROTOS_H */
diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c
index f153d137411..9912105ecfa 100644
--- a/gcc/config/mips/mips.c
+++ b/gcc/config/mips/mips.c
@@ -261,18 +261,29 @@ struct mips_frame_info GTY(()) {
/* Likewise FPR X. */
unsigned int fmask;
- /* The number of GPRs and FPRs saved. */
+ /* Likewise doubleword accumulator X ($acX). */
+ unsigned int acc_mask;
+
+ /* The number of GPRs, FPRs, doubleword accumulators and COP0
+ registers saved. */
unsigned int num_gp;
unsigned int num_fp;
+ unsigned int num_acc;
+ unsigned int num_cop0_regs;
- /* The offset of the topmost GPR and FPR save slots from the top of
- the frame, or zero if no such slots are needed. */
+ /* The offset of the topmost GPR, FPR, accumulator and COP0-register
+ save slots from the top of the frame, or zero if no such slots are
+ needed. */
HOST_WIDE_INT gp_save_offset;
HOST_WIDE_INT fp_save_offset;
+ HOST_WIDE_INT acc_save_offset;
+ HOST_WIDE_INT cop0_save_offset;
/* Likewise, but giving offsets from the bottom of the frame. */
HOST_WIDE_INT gp_sp_offset;
HOST_WIDE_INT fp_sp_offset;
+ HOST_WIDE_INT acc_sp_offset;
+ HOST_WIDE_INT cop0_sp_offset;
/* The offset of arg_pointer_rtx from frame_pointer_rtx. */
HOST_WIDE_INT arg_pointer_offset;
@@ -310,6 +321,20 @@ struct machine_function GTY(()) {
/* True if we have emitted an instruction to initialize
mips16_gp_pseudo_rtx. */
bool initialized_mips16_gp_pseudo_p;
+
+ /* True if this is an interrupt handler. */
+ bool interrupt_handler_p;
+
+ /* True if this is an interrupt handler that uses shadow registers. */
+ bool use_shadow_register_set_p;
+
+ /* True if this is an interrupt handler that should keep interrupts
+ masked. */
+ bool keep_interrupts_masked_p;
+
+ /* True if this is an interrupt handler that should use DERET
+ instead of ERET. */
+ bool use_debug_exception_return_p;
};
/* Information about a single argument. */
@@ -554,6 +579,11 @@ const struct attribute_spec mips_attribute_table[] = {
code generation but don't carry other semantics. */
{ "mips16", 0, 0, true, false, false, NULL },
{ "nomips16", 0, 0, true, false, false, NULL },
+ /* Allow functions to be specified as interrupt handlers */
+ { "interrupt", 0, 0, false, true, true, NULL },
+ { "use_shadow_register_set", 0, 0, false, true, true, NULL },
+ { "keep_interrupts_masked", 0, 0, false, true, true, NULL },
+ { "use_debug_exception_return", 0, 0, false, true, true, NULL },
{ NULL, 0, 0, false, false, false, NULL }
};
@@ -1172,6 +1202,42 @@ mips_nomips16_decl_p (const_tree decl)
return lookup_attribute ("nomips16", DECL_ATTRIBUTES (decl)) != NULL;
}
+/* Check if the interrupt attribute is set for a function. */
+
+static bool
+mips_interrupt_type_p (tree type)
+{
+ return lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type)) != NULL;
+}
+
+/* Check if the attribute to use shadow register set is set for a function. */
+
+static bool
+mips_use_shadow_register_set_p (tree type)
+{
+ return lookup_attribute ("use_shadow_register_set",
+ TYPE_ATTRIBUTES (type)) != NULL;
+}
+
+/* Check if the attribute to keep interrupts masked is set for a function. */
+
+static bool
+mips_keep_interrupts_masked_p (tree type)
+{
+ return lookup_attribute ("keep_interrupts_masked",
+ TYPE_ATTRIBUTES (type)) != NULL;
+}
+
+/* Check if the attribute to use debug exception return is set for
+ a function. */
+
+static bool
+mips_use_debug_exception_return_p (tree type)
+{
+ return lookup_attribute ("use_debug_exception_return",
+ TYPE_ATTRIBUTES (type)) != NULL;
+}
+
/* Return true if function DECL is a MIPS16 function. Return the ambient
setting if DECL is null. */
@@ -6188,6 +6254,11 @@ mips_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
if (!TARGET_SIBCALLS)
return false;
+ /* Interrupt handlers need special epilogue code and therefore can't
+ use sibcalls. */
+ if (mips_interrupt_type_p (TREE_TYPE (current_function_decl)))
+ return false;
+
/* We can't do a sibcall if the called function is a MIPS16 function
because there is no direct "jx" instruction equivalent to "jalx" to
switch the ISA mode. We only care about cases where the sibling
@@ -7229,7 +7300,11 @@ mips_print_operand (FILE *file, rtx op, int letter)
|| (letter == 'L' && TARGET_BIG_ENDIAN)
|| letter == 'D')
regno++;
- fprintf (file, "%s", reg_names[regno]);
+ /* We need to print $0 .. $31 for COP0 registers. */
+ if (COP0_REG_P (regno))
+ fprintf (file, "$%s", &reg_names[regno][4]);
+ else
+ fprintf (file, "%s", reg_names[regno]);
}
break;
@@ -8436,12 +8511,53 @@ mips_global_pointer (void)
return GLOBAL_POINTER_REGNUM;
}
+/* Return true if REGNO is a register that is ordinarily call-clobbered
+ but must nevertheless be preserved by an interrupt handler. */
+
+static bool
+mips_interrupt_extra_call_saved_reg_p (unsigned int regno)
+{
+ if (MD_REG_P (regno))
+ return true;
+
+ if (TARGET_DSP && DSP_ACC_REG_P (regno))
+ return true;
+
+ if (GP_REG_P (regno) && !cfun->machine->use_shadow_register_set_p)
+ {
+ /* $0 is hard-wired. */
+ if (regno == GP_REG_FIRST)
+ return false;
+
+ /* The interrupt handler can treat kernel registers as
+ scratch registers. */
+ if (KERNEL_REG_P (regno))
+ return false;
+
+ /* The function will return the stack pointer to its original value
+ anyway. */
+ if (regno == STACK_POINTER_REGNUM)
+ return false;
+
+ /* Otherwise, return true for registers that aren't ordinarily
+ call-clobbered. */
+ return call_really_used_regs[regno];
+ }
+
+ return false;
+}
+
/* Return true if the current function should treat register REGNO
as call-saved. */
static bool
mips_cfun_call_saved_reg_p (unsigned int regno)
{
+ /* Interrupt handlers need to save extra registers. */
+ if (cfun->machine->interrupt_handler_p
+ && mips_interrupt_extra_call_saved_reg_p (regno))
+ return true;
+
/* call_insns preserve $28 unless they explicitly say otherwise,
so call_really_used_regs[] treats $28 as call-saved. However,
we want the ABI property rather than the default call_insn
@@ -8490,6 +8606,13 @@ mips_cfun_might_clobber_call_saved_reg_p (unsigned int regno)
if (regno == GP_REG_FIRST + 31 && mips16_cfun_returns_in_fpr_p ())
return true;
+ /* If REGNO is ordinarily call-clobbered, we must assume that any
+ called function could modify it. */
+ if (cfun->machine->interrupt_handler_p
+ && !current_function_is_leaf
+ && mips_interrupt_extra_call_saved_reg_p (regno))
+ return true;
+
return false;
}
@@ -8545,6 +8668,14 @@ mips_save_reg_p (unsigned int regno)
C | callee-allocated save area |
| for register varargs |
| |
+ +-------------------------------+ <-- frame_pointer_rtx
+ | | + cop0_sp_offset
+ | COP0 reg save area | + UNITS_PER_WORD
+ | |
+ +-------------------------------+ <-- frame_pointer_rtx + acc_sp_offset
+ | | + UNITS_PER_WORD
+ | accumulator save area |
+ | |
+-------------------------------+ <-- frame_pointer_rtx + fp_sp_offset
| | + UNITS_PER_HWFPVALUE
| FPR save area |
@@ -8588,6 +8719,28 @@ mips_compute_frame_info (void)
HOST_WIDE_INT offset, size;
unsigned int regno, i;
+ /* Set this function's interrupt properties. */
+ if (mips_interrupt_type_p (TREE_TYPE (current_function_decl)))
+ {
+ if (!ISA_MIPS32R2)
+ error ("the %<interrupt%> attribute requires a MIPS32r2 processor");
+ else if (TARGET_HARD_FLOAT)
+ error ("the %<interrupt%> attribute requires %<-msoft-float%>");
+ else if (TARGET_MIPS16)
+ error ("interrupt handlers cannot be MIPS16 functions");
+ else
+ {
+ cfun->machine->interrupt_handler_p = true;
+ cfun->machine->use_shadow_register_set_p =
+ mips_use_shadow_register_set_p (TREE_TYPE (current_function_decl));
+ cfun->machine->keep_interrupts_masked_p =
+ mips_keep_interrupts_masked_p (TREE_TYPE (current_function_decl));
+ cfun->machine->use_debug_exception_return_p =
+ mips_use_debug_exception_return_p (TREE_TYPE
+ (current_function_decl));
+ }
+ }
+
frame = &cfun->machine->frame;
memset (frame, 0, sizeof (*frame));
size = get_frame_size ();
@@ -8657,7 +8810,7 @@ mips_compute_frame_info (void)
}
/* Find out which FPRs we need to save. This loop must iterate over
- the same space as its companion in mips_for_each_saved_reg. */
+ the same space as its companion in mips_for_each_saved_gpr_and_fpr. */
if (TARGET_HARD_FLOAT)
for (regno = FP_REG_FIRST; regno <= FP_REG_LAST; regno += MAX_FPRS_PER_FMT)
if (mips_save_reg_p (regno))
@@ -8673,6 +8826,47 @@ mips_compute_frame_info (void)
frame->fp_sp_offset = offset - UNITS_PER_HWFPVALUE;
}
+ /* Add in space for the interrupt context information. */
+ if (cfun->machine->interrupt_handler_p)
+ {
+ /* Check HI/LO. */
+ if (mips_save_reg_p (LO_REGNUM) || mips_save_reg_p (HI_REGNUM))
+ {
+ frame->num_acc++;
+ frame->acc_mask |= (1 << 0);
+ }
+
+ /* Check accumulators 1, 2, 3. */
+ for (i = DSP_ACC_REG_FIRST; i <= DSP_ACC_REG_LAST; i += 2)
+ if (mips_save_reg_p (i) || mips_save_reg_p (i + 1))
+ {
+ frame->num_acc++;
+ frame->acc_mask |= 1 << (((i - DSP_ACC_REG_FIRST) / 2) + 1);
+ }
+
+ /* All interrupt context functions need space to preserve STATUS. */
+ frame->num_cop0_regs++;
+
+ /* If we don't keep interrupts masked, we need to save EPC. */
+ if (!cfun->machine->keep_interrupts_masked_p)
+ frame->num_cop0_regs++;
+ }
+
+ /* Move above the accumulator save area. */
+ if (frame->num_acc > 0)
+ {
+ /* Each accumulator needs 2 words. */
+ offset += frame->num_acc * 2 * UNITS_PER_WORD;
+ frame->acc_sp_offset = offset - UNITS_PER_WORD;
+ }
+
+ /* Move above the COP0 register save area. */
+ if (frame->num_cop0_regs > 0)
+ {
+ offset += frame->num_cop0_regs * UNITS_PER_WORD;
+ frame->cop0_sp_offset = offset - UNITS_PER_WORD;
+ }
+
/* Move above the callee-allocated varargs save area. */
offset += MIPS_STACK_ALIGN (cfun->machine->varargs_size);
frame->arg_pointer_offset = offset;
@@ -8686,6 +8880,10 @@ mips_compute_frame_info (void)
frame->gp_save_offset = frame->gp_sp_offset - offset;
if (frame->fp_sp_offset > 0)
frame->fp_save_offset = frame->fp_sp_offset - offset;
+ if (frame->acc_sp_offset > 0)
+ frame->acc_save_offset = frame->acc_sp_offset - offset;
+ if (frame->num_cop0_regs > 0)
+ frame->cop0_save_offset = frame->cop0_sp_offset - offset;
/* MIPS16 code offsets the frame pointer by the size of the outgoing
arguments. This tends to increase the chances of using unextended
@@ -8882,12 +9080,41 @@ mips_save_restore_reg (enum machine_mode mode, int regno,
fn (gen_rtx_REG (mode, regno), mem);
}
+/* Call FN for each accumlator that is saved by the current function.
+ SP_OFFSET is the offset of the current stack pointer from the start
+ of the frame. */
+
+static void
+mips_for_each_saved_acc (HOST_WIDE_INT sp_offset, mips_save_restore_fn fn)
+{
+ HOST_WIDE_INT offset;
+ int regno;
+
+ offset = cfun->machine->frame.acc_sp_offset - sp_offset;
+ if (BITSET_P (cfun->machine->frame.acc_mask, 0))
+ {
+ mips_save_restore_reg (word_mode, LO_REGNUM, offset, fn);
+ offset -= UNITS_PER_WORD;
+ mips_save_restore_reg (word_mode, HI_REGNUM, offset, fn);
+ offset -= UNITS_PER_WORD;
+ }
+
+ for (regno = DSP_ACC_REG_FIRST; regno <= DSP_ACC_REG_LAST; regno++)
+ if (BITSET_P (cfun->machine->frame.acc_mask,
+ ((regno - DSP_ACC_REG_FIRST) / 2) + 1))
+ {
+ mips_save_restore_reg (word_mode, regno, offset, fn);
+ offset -= UNITS_PER_WORD;
+ }
+}
+
/* Call FN for each register that is saved by the current function.
SP_OFFSET is the offset of the current stack pointer from the start
of the frame. */
static void
-mips_for_each_saved_reg (HOST_WIDE_INT sp_offset, mips_save_restore_fn fn)
+mips_for_each_saved_gpr_and_fpr (HOST_WIDE_INT sp_offset,
+ mips_save_restore_fn fn)
{
enum machine_mode fpr_mode;
HOST_WIDE_INT offset;
@@ -9075,13 +9302,24 @@ mips_save_reg (rtx reg, rtx mem)
}
else
{
- if (TARGET_MIPS16
- && REGNO (reg) != GP_REG_FIRST + 31
- && !M16_REG_P (REGNO (reg)))
+ if (REGNO (reg) == HI_REGNUM)
{
- /* Save a non-MIPS16 register by moving it through a temporary.
- We don't need to do this for $31 since there's a special
- instruction for it. */
+ if (TARGET_64BIT)
+ emit_insn (gen_mfhidi_ti (MIPS_PROLOGUE_TEMP (DImode),
+ gen_rtx_REG (TImode, MD_REG_FIRST)));
+ else
+ emit_insn (gen_mfhisi_di (MIPS_PROLOGUE_TEMP (SImode),
+ gen_rtx_REG (DImode, MD_REG_FIRST)));
+ mips_emit_move (mem, MIPS_PROLOGUE_TEMP (GET_MODE (reg)));
+ }
+ else if ((TARGET_MIPS16
+ && REGNO (reg) != GP_REG_FIRST + 31
+ && !M16_REG_P (REGNO (reg)))
+ || ACC_REG_P (REGNO (reg)))
+ {
+ /* If the register has no direct store instruction, move it
+ through a temporary. Note that there's a special MIPS16
+ instruction to save $31. */
mips_emit_move (MIPS_PROLOGUE_TEMP (GET_MODE (reg)), reg);
mips_emit_move (mem, MIPS_PROLOGUE_TEMP (GET_MODE (reg)));
}
@@ -9153,6 +9391,14 @@ mips_emit_loadgp (void)
emit_insn (gen_loadgp_blockage ());
}
+/* A for_each_rtx callback. Stop the search if *X is a kernel register. */
+
+static int
+mips_kernel_reg_p (rtx *x, void *data ATTRIBUTE_UNUSED)
+{
+ return GET_CODE (*x) == REG && KERNEL_REG_P (REGNO (*x));
+}
+
/* Expand the "prologue" pattern. */
void
@@ -9172,7 +9418,8 @@ mips_expand_prologue (void)
/* Save the registers. Allocate up to MIPS_MAX_FIRST_STACK_STEP
bytes beforehand; this is enough to cover the register save area
without going out of range. */
- if ((frame->mask | frame->fmask) != 0)
+ if (((frame->mask | frame->fmask | frame->acc_mask) != 0)
+ || frame->num_cop0_regs > 0)
{
HOST_WIDE_INT step1;
@@ -9203,12 +9450,97 @@ mips_expand_prologue (void)
}
else
{
- insn = gen_add3_insn (stack_pointer_rtx,
- stack_pointer_rtx,
- GEN_INT (-step1));
- RTX_FRAME_RELATED_P (emit_insn (insn)) = 1;
- size -= step1;
- mips_for_each_saved_reg (size, mips_save_reg);
+ if (cfun->machine->interrupt_handler_p)
+ {
+ HOST_WIDE_INT offset;
+ rtx mem;
+
+ /* If this interrupt is using a shadow register set, we need to
+ get the stack pointer from the previous register set. */
+ if (cfun->machine->use_shadow_register_set_p)
+ emit_insn (gen_mips_rdpgpr (stack_pointer_rtx,
+ stack_pointer_rtx));
+
+ if (!cfun->machine->keep_interrupts_masked_p)
+ {
+ /* Move from COP0 Cause to K0. */
+ emit_insn (gen_cop0_move (gen_rtx_REG (SImode, K0_REG_NUM),
+ gen_rtx_REG (SImode,
+ COP0_CAUSE_REG_NUM)));
+ /* Move from COP0 EPC to K1. */
+ emit_insn (gen_cop0_move (gen_rtx_REG (SImode, K1_REG_NUM),
+ gen_rtx_REG (SImode,
+ COP0_EPC_REG_NUM)));
+ }
+
+ /* Allocate the first part of the frame. */
+ insn = gen_add3_insn (stack_pointer_rtx, stack_pointer_rtx,
+ GEN_INT (-step1));
+ RTX_FRAME_RELATED_P (emit_insn (insn)) = 1;
+ size -= step1;
+
+ /* Start at the uppermost location for saving. */
+ offset = frame->cop0_sp_offset - size;
+ if (!cfun->machine->keep_interrupts_masked_p)
+ {
+ /* Push EPC into its stack slot. */
+ mem = gen_frame_mem (word_mode,
+ plus_constant (stack_pointer_rtx,
+ offset));
+ mips_emit_move (mem, gen_rtx_REG (word_mode, K1_REG_NUM));
+ offset -= UNITS_PER_WORD;
+ }
+
+ /* Move from COP0 Status to K1. */
+ emit_insn (gen_cop0_move (gen_rtx_REG (SImode, K1_REG_NUM),
+ gen_rtx_REG (SImode,
+ COP0_STATUS_REG_NUM)));
+
+ /* Right justify the RIPL in k0. */
+ if (!cfun->machine->keep_interrupts_masked_p)
+ emit_insn (gen_lshrsi3 (gen_rtx_REG (SImode, K0_REG_NUM),
+ gen_rtx_REG (SImode, K0_REG_NUM),
+ GEN_INT (CAUSE_IPL)));
+
+ /* Push Status into its stack slot. */
+ mem = gen_frame_mem (word_mode,
+ plus_constant (stack_pointer_rtx, offset));
+ mips_emit_move (mem, gen_rtx_REG (word_mode, K1_REG_NUM));
+ offset -= UNITS_PER_WORD;
+
+ /* Insert the RIPL into our copy of SR (k1) as the new IPL. */
+ if (!cfun->machine->keep_interrupts_masked_p)
+ emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM),
+ GEN_INT (6),
+ GEN_INT (SR_IPL),
+ gen_rtx_REG (SImode, K0_REG_NUM)));
+
+ if (!cfun->machine->keep_interrupts_masked_p)
+ /* Enable interrupts by clearing the KSU ERL and EXL bits.
+ IE is already the correct value, so we don't have to do
+ anything explicit. */
+ emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM),
+ GEN_INT (4),
+ GEN_INT (SR_EXL),
+ gen_rtx_REG (SImode, GP_REG_FIRST)));
+ else
+ /* Disable interrupts by clearing the KSU, ERL, EXL,
+ and IE bits. */
+ emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM),
+ GEN_INT (5),
+ GEN_INT (SR_IE),
+ gen_rtx_REG (SImode, GP_REG_FIRST)));
+ }
+ else
+ {
+ insn = gen_add3_insn (stack_pointer_rtx,
+ stack_pointer_rtx,
+ GEN_INT (-step1));
+ RTX_FRAME_RELATED_P (emit_insn (insn)) = 1;
+ size -= step1;
+ }
+ mips_for_each_saved_acc (size, mips_save_reg);
+ mips_for_each_saved_gpr_and_fpr (size, mips_save_reg);
}
}
@@ -9293,6 +9625,20 @@ mips_expand_prologue (void)
pic_offset_table_rtx);
}
+ /* We need to search back to the last use of K0 or K1. */
+ if (cfun->machine->interrupt_handler_p)
+ {
+ for (insn = get_last_insn (); insn != NULL_RTX; insn = PREV_INSN (insn))
+ if (INSN_P (insn)
+ && for_each_rtx (&PATTERN (insn), mips_kernel_reg_p, NULL))
+ break;
+ /* Emit a move from K1 to COP0 Status after insn. */
+ gcc_assert (insn != NULL_RTX);
+ emit_insn_after (gen_cop0_move (gen_rtx_REG (SImode, COP0_STATUS_REG_NUM),
+ gen_rtx_REG (SImode, K1_REG_NUM)),
+ insn);
+ }
+
/* If we are profiling, make sure no instructions are scheduled before
the call to mcount. */
if (crtl->profile)
@@ -9309,7 +9655,20 @@ mips_restore_reg (rtx reg, rtx mem)
if (TARGET_MIPS16 && REGNO (reg) == GP_REG_FIRST + 31)
reg = gen_rtx_REG (GET_MODE (reg), GP_REG_FIRST + 7);
- if (TARGET_MIPS16 && !M16_REG_P (REGNO (reg)))
+ if (REGNO (reg) == HI_REGNUM)
+ {
+ mips_emit_move (MIPS_EPILOGUE_TEMP (GET_MODE (reg)), mem);
+ if (TARGET_64BIT)
+ emit_insn (gen_mthisi_di (gen_rtx_REG (TImode, MD_REG_FIRST),
+ MIPS_EPILOGUE_TEMP (DImode),
+ gen_rtx_REG (DImode, LO_REGNUM)));
+ else
+ emit_insn (gen_mthisi_di (gen_rtx_REG (DImode, MD_REG_FIRST),
+ MIPS_EPILOGUE_TEMP (SImode),
+ gen_rtx_REG (SImode, LO_REGNUM)));
+ }
+ else if ((TARGET_MIPS16 && !M16_REG_P (REGNO (reg)))
+ || ACC_REG_P (REGNO (reg)))
{
/* Can't restore directly; move through a temporary. */
mips_emit_move (MIPS_EPILOGUE_TEMP (GET_MODE (reg)), mem);
@@ -9345,7 +9704,7 @@ mips_expand_epilogue (bool sibcall_p)
{
const struct mips_frame_info *frame;
HOST_WIDE_INT step1, step2;
- rtx base, target;
+ rtx base, target, insn;
if (!sibcall_p && mips_can_use_return_insn ())
{
@@ -9378,7 +9737,8 @@ mips_expand_epilogue (bool sibcall_p)
/* If we need to restore registers, deallocate as much stack as
possible in the second step without going out of range. */
- if ((frame->mask | frame->fmask) != 0)
+ if ((frame->mask | frame->fmask | frame->acc_mask) != 0
+ || frame->num_cop0_regs > 0)
{
step2 = MIN (step1, MIPS_MAX_FIRST_STACK_STEP);
step1 -= step2;
@@ -9440,13 +9800,53 @@ mips_expand_epilogue (bool sibcall_p)
else
{
/* Restore the registers. */
- mips_for_each_saved_reg (frame->total_size - step2, mips_restore_reg);
+ mips_for_each_saved_acc (frame->total_size - step2, mips_restore_reg);
+ mips_for_each_saved_gpr_and_fpr (frame->total_size - step2,
+ mips_restore_reg);
- /* Deallocate the final bit of the frame. */
- if (step2 > 0)
- emit_insn (gen_add3_insn (stack_pointer_rtx,
- stack_pointer_rtx,
- GEN_INT (step2)));
+ if (cfun->machine->interrupt_handler_p)
+ {
+ HOST_WIDE_INT offset;
+ rtx mem;
+
+ offset = frame->cop0_sp_offset - (frame->total_size - step2);
+ if (!cfun->machine->keep_interrupts_masked_p)
+ {
+ /* Restore the original EPC. */
+ mem = gen_frame_mem (word_mode,
+ plus_constant (stack_pointer_rtx, offset));
+ mips_emit_move (gen_rtx_REG (word_mode, K0_REG_NUM), mem);
+ offset -= UNITS_PER_WORD;
+
+ /* Move to COP0 EPC. */
+ emit_insn (gen_cop0_move (gen_rtx_REG (SImode, COP0_EPC_REG_NUM),
+ gen_rtx_REG (SImode, K0_REG_NUM)));
+ }
+
+ /* Restore the original Status. */
+ mem = gen_frame_mem (word_mode,
+ plus_constant (stack_pointer_rtx, offset));
+ mips_emit_move (gen_rtx_REG (word_mode, K0_REG_NUM), mem);
+ offset -= UNITS_PER_WORD;
+
+ /* If we don't use shoadow register set, we need to update SP. */
+ if (!cfun->machine->use_shadow_register_set_p && step2 > 0)
+ emit_insn (gen_add3_insn (stack_pointer_rtx,
+ stack_pointer_rtx,
+ GEN_INT (step2)));
+
+ /* Move to COP0 Status. */
+ emit_insn (gen_cop0_move (gen_rtx_REG (SImode, COP0_STATUS_REG_NUM),
+ gen_rtx_REG (SImode, K0_REG_NUM)));
+ }
+ else
+ {
+ /* Deallocate the final bit of the frame. */
+ if (step2 > 0)
+ emit_insn (gen_add3_insn (stack_pointer_rtx,
+ stack_pointer_rtx,
+ GEN_INT (step2)));
+ }
}
/* Add in the __builtin_eh_return stack adjustment. We need to
@@ -9469,18 +9869,44 @@ mips_expand_epilogue (bool sibcall_p)
if (!sibcall_p)
{
- unsigned int regno;
-
- /* When generating MIPS16 code, the normal mips_for_each_saved_reg
- path will restore the return address into $7 rather than $31. */
- if (TARGET_MIPS16
- && !GENERATE_MIPS16E_SAVE_RESTORE
- && BITSET_P (frame->mask, 31))
- regno = GP_REG_FIRST + 7;
- else
- regno = GP_REG_FIRST + 31;
mips_expand_before_return ();
- emit_jump_insn (gen_return_internal (gen_rtx_REG (Pmode, regno)));
+ if (cfun->machine->interrupt_handler_p)
+ {
+ /* Interrupt handlers generate eret or deret. */
+ if (cfun->machine->use_debug_exception_return_p)
+ emit_jump_insn (gen_mips_deret ());
+ else
+ emit_jump_insn (gen_mips_eret ());
+ }
+ else
+ {
+ unsigned int regno;
+
+ /* When generating MIPS16 code, the normal
+ mips_for_each_saved_gpr_and_fpr path will restore the return
+ address into $7 rather than $31. */
+ if (TARGET_MIPS16
+ && !GENERATE_MIPS16E_SAVE_RESTORE
+ && BITSET_P (frame->mask, 31))
+ regno = GP_REG_FIRST + 7;
+ else
+ regno = GP_REG_FIRST + 31;
+ emit_jump_insn (gen_return_internal (gen_rtx_REG (Pmode, regno)));
+ }
+ }
+
+ /* Search from the beginning to the first use of K0 or K1. */
+ if (cfun->machine->interrupt_handler_p
+ && !cfun->machine->keep_interrupts_masked_p)
+ {
+ for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
+ if (INSN_P (insn)
+ && for_each_rtx (&PATTERN(insn), mips_kernel_reg_p, NULL))
+ break;
+ gcc_assert (insn != NULL_RTX);
+ /* Insert disable interrupts before the first use of K0 or K1. */
+ emit_insn_before (gen_mips_di (), insn);
+ emit_insn_before (gen_mips_ehb (), insn);
}
}
@@ -9491,6 +9917,10 @@ mips_expand_epilogue (bool sibcall_p)
bool
mips_can_use_return_insn (void)
{
+ /* Interrupt handlers need to go through the epilogue. */
+ if (cfun->machine->interrupt_handler_p)
+ return false;
+
if (!reload_completed)
return false;
@@ -14242,6 +14672,31 @@ mips_order_regs_for_local_alloc (void)
reg_alloc_order[24] = 0;
}
}
+
+/* Implement EPILOGUE_USES. */
+
+bool
+mips_epilogue_uses (unsigned int regno)
+{
+ /* Say that the epilogue uses the return address register. Note that
+ in the case of sibcalls, the values "used by the epilogue" are
+ considered live at the start of the called function. */
+ if (regno == 31)
+ return true;
+
+ /* If using a GOT, say that the epilogue also uses GOT_VERSION_REGNUM.
+ See the comment above load_call<mode> for details. */
+ if (TARGET_USE_GOT && (regno) == GOT_VERSION_REGNUM)
+ return true;
+
+ /* An interrupt handler must preserve some registers that are
+ ordinarily call-clobbered. */
+ if (cfun->machine->interrupt_handler_p
+ && mips_interrupt_extra_call_saved_reg_p (regno))
+ return true;
+
+ return false;
+}
/* Initialize the GCC target structure. */
#undef TARGET_ASM_ALIGNED_HI_OP
diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
index c2533c49e9f..fbcfdca61e9 100644
--- a/gcc/config/mips/mips.h
+++ b/gcc/config/mips/mips.h
@@ -1622,6 +1622,9 @@ enum mips_code_readable_setting {
#define GP_REG_LAST 31
#define GP_REG_NUM (GP_REG_LAST - GP_REG_FIRST + 1)
#define GP_DBX_FIRST 0
+#define K0_REG_NUM (GP_REG_FIRST + 26)
+#define K1_REG_NUM (GP_REG_FIRST + 27)
+#define KERNEL_REG_P(REGNO) (IN_RANGE (REGNO, K0_REG_NUM, K1_REG_NUM))
#define FP_REG_FIRST 32
#define FP_REG_LAST 63
@@ -1649,6 +1652,10 @@ enum mips_code_readable_setting {
#define COP0_REG_LAST 111
#define COP0_REG_NUM (COP0_REG_LAST - COP0_REG_FIRST + 1)
+#define COP0_STATUS_REG_NUM (COP0_REG_FIRST + 12)
+#define COP0_CAUSE_REG_NUM (COP0_REG_FIRST + 13)
+#define COP0_EPC_REG_NUM (COP0_REG_FIRST + 14)
+
#define COP2_REG_FIRST 112
#define COP2_REG_LAST 143
#define COP2_REG_NUM (COP2_REG_LAST - COP2_REG_FIRST + 1)
@@ -1667,6 +1674,17 @@ enum mips_code_readable_setting {
#define HI_REGNUM (TARGET_BIG_ENDIAN ? MD_REG_FIRST : MD_REG_FIRST + 1)
#define LO_REGNUM (TARGET_BIG_ENDIAN ? MD_REG_FIRST + 1 : MD_REG_FIRST)
+/* A few bitfield locations for the coprocessor registers. */
+/* Request Interrupt Priority Level is from bit 10 to bit 15 of
+ the cause register for the EIC interrupt mode. */
+#define CAUSE_IPL 10
+/* Interrupt Priority Level is from bit 10 to bit 15 of the status register. */
+#define SR_IPL 10
+/* Exception Level is at bit 1 of the status register. */
+#define SR_EXL 1
+/* Interrupt Enable is at bit 0 of the status register. */
+#define SR_IE 0
+
/* FPSW_REGNUM is the single condition code used if !ISA_HAS_8CC.
If ISA_HAS_8CC, it should not be used, and an arbitrary ST_REG
should be used instead. */
@@ -1754,11 +1772,18 @@ enum mips_code_readable_setting {
incoming arguments, the static chain pointer, or the frame pointer.
The epilogue temporary mustn't conflict with the return registers,
the PIC call register ($25), the frame pointer, the EH stack adjustment,
- or the EH data registers. */
+ or the EH data registers.
+
+ If we're generating interrupt handlers, we use K0 as a temporary register
+ in prologue/epilogue code. */
#define MIPS16_PIC_TEMP_REGNUM (GP_REG_FIRST + 2)
-#define MIPS_PROLOGUE_TEMP_REGNUM (GP_REG_FIRST + 3)
-#define MIPS_EPILOGUE_TEMP_REGNUM (GP_REG_FIRST + (TARGET_MIPS16 ? 6 : 8))
+#define MIPS_PROLOGUE_TEMP_REGNUM \
+ (cfun->machine->interrupt_handler_p ? K0_REG_NUM : GP_REG_FIRST + 3)
+#define MIPS_EPILOGUE_TEMP_REGNUM \
+ (cfun->machine->interrupt_handler_p \
+ ? K0_REG_NUM \
+ : GP_REG_FIRST + (TARGET_MIPS16 ? 6 : 8))
#define MIPS16_PIC_TEMP gen_rtx_REG (Pmode, MIPS16_PIC_TEMP_REGNUM)
#define MIPS_PROLOGUE_TEMP(MODE) gen_rtx_REG (MODE, MIPS_PROLOGUE_TEMP_REGNUM)
@@ -2284,14 +2309,7 @@ typedef struct mips_args {
(mips_abi == ABI_EABI && UNITS_PER_FPVALUE >= UNITS_PER_DOUBLE)
-/* Say that the epilogue uses the return address register. Note that
- in the case of sibcalls, the values "used by the epilogue" are
- considered live at the start of the called function.
-
- If using a GOT, say that the epilogue also uses GOT_VERSION_REGNUM.
- See the comment above load_call<mode> for details. */
-#define EPILOGUE_USES(REGNO) \
- ((REGNO) == 31 || (TARGET_USE_GOT && (REGNO) == GOT_VERSION_REGNUM))
+#define EPILOGUE_USES(REGNO) mips_epilogue_uses (REGNO)
/* Treat LOC as a byte offset from the stack pointer and round it up
to the next fully-aligned offset. */
diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md
index 10572743e75..8a6719466d3 100644
--- a/gcc/config/mips/mips.md
+++ b/gcc/config/mips/mips.md
@@ -67,6 +67,12 @@
(UNSPEC_SET_GOT_VERSION 46)
(UNSPEC_UPDATE_GOT_VERSION 47)
(UNSPEC_COPYGP 48)
+ (UNSPEC_ERET 49)
+ (UNSPEC_DERET 50)
+ (UNSPEC_DI 51)
+ (UNSPEC_EHB 52)
+ (UNSPEC_RDPGPR 53)
+ (UNSPEC_COP0 54)
(UNSPEC_ADDRESS_FIRST 100)
@@ -5679,6 +5685,60 @@
[(set_attr "type" "jump")
(set_attr "mode" "none")])
+;; Exception return.
+(define_insn "mips_eret"
+ [(return)
+ (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
+ ""
+ "eret"
+ [(set_attr "type" "trap")
+ (set_attr "mode" "none")])
+
+;; Debug exception return.
+(define_insn "mips_deret"
+ [(return)
+ (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
+ ""
+ "deret"
+ [(set_attr "type" "trap")
+ (set_attr "mode" "none")])
+
+;; Disable interrupts.
+(define_insn "mips_di"
+ [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
+ ""
+ "di"
+ [(set_attr "type" "trap")
+ (set_attr "mode" "none")])
+
+;; Execution hazard barrier.
+(define_insn "mips_ehb"
+ [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
+ ""
+ "ehb"
+ [(set_attr "type" "trap")
+ (set_attr "mode" "none")])
+
+;; Read GPR from previous shadow register set.
+(define_insn "mips_rdpgpr"
+ [(set (match_operand:SI 0 "register_operand" "=d")
+ (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d")]
+ UNSPEC_RDPGPR))]
+ ""
+ "rdpgpr\t%0,%1"
+ [(set_attr "type" "move")
+ (set_attr "mode" "SI")])
+
+;; Move involving COP0 registers.
+(define_insn "cop0_move"
+ [(set (match_operand:SI 0 "register_operand" "=B,d")
+ (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
+ UNSPEC_COP0))]
+ ""
+{ return mips_output_move (operands[0], operands[1]); }
+ [(set_attr "type" "mtc,mfc")
+ (set_attr "mode" "SI")])
+
;; This is used in compiling the unwind routines.
(define_expand "eh_return"
[(use (match_operand 0 "general_operand"))]
diff --git a/gcc/config/mips/sde.h b/gcc/config/mips/sde.h
index 3640883e042..d2a32967b75 100644
--- a/gcc/config/mips/sde.h
+++ b/gcc/config/mips/sde.h
@@ -90,7 +90,8 @@ along with GCC; see the file COPYING3. If not see
/* Use $5 as a temporary for both MIPS16 and non-MIPS16. */
#undef MIPS_EPILOGUE_TEMP_REGNUM
-#define MIPS_EPILOGUE_TEMP_REGNUM (GP_REG_FIRST + 5)
+#define MIPS_EPILOGUE_TEMP_REGNUM \
+ (cfun->machine->interrupt_handler_p ? K0_REG_NUM : GP_REG_FIRST + 5)
/* Using long will always be right for size_t and ptrdiff_t, since
sizeof(long) must equal sizeof(void *), following from the setting
diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
index ad2eb4b7fea..24c63d35cfb 100644
--- a/gcc/config/rs6000/linux64.h
+++ b/gcc/config/rs6000/linux64.h
@@ -99,7 +99,7 @@ extern int dot_symbols;
} \
if (TARGET_PROTOTYPE) \
{ \
- TARGET_PROTOTYPE = 0; \
+ target_prototype = 0; \
error (INVALID_64BIT, "prototype"); \
} \
if ((target_flags & MASK_POWERPC64) == 0) \
@@ -134,6 +134,10 @@ extern int dot_symbols;
#undef ASM_SPEC
#undef LINK_OS_LINUX_SPEC
+/* FIXME: This will quite possibly choose the wrong dynamic linker. */
+#undef LINK_OS_GNU_SPEC
+#define LINK_OS_GNU_SPEC LINK_OS_LINUX_SPEC
+
#ifndef RS6000_BI_ARCH
#define ASM_DEFAULT_SPEC "-mppc64"
#define ASM_SPEC "%(asm_spec64) %(asm_spec_common)"
diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
index 1deb0eb8cfd..31028298c0e 100644
--- a/gcc/config/rs6000/sysv4.h
+++ b/gcc/config/rs6000/sysv4.h
@@ -54,6 +54,7 @@ extern enum rs6000_sdata_type rs6000_sdata;
#define TARGET_BITFIELD_TYPE (! TARGET_NO_BITFIELD_TYPE)
#define TARGET_BIG_ENDIAN (! TARGET_LITTLE_ENDIAN)
+#define TARGET_PROTOTYPE target_prototype
#define TARGET_NO_PROTOTYPE (! TARGET_PROTOTYPE)
#define TARGET_NO_TOC (! TARGET_TOC)
#define TARGET_NO_EABI (! TARGET_EABI)
diff --git a/gcc/config/rs6000/sysv4.opt b/gcc/config/rs6000/sysv4.opt
index 85e0018ac78..1ead31d4c01 100644
--- a/gcc/config/rs6000/sysv4.opt
+++ b/gcc/config/rs6000/sysv4.opt
@@ -74,7 +74,7 @@ Target RejectNegative
no description yet
mprototype
-Target Var(TARGET_PROTOTYPE)
+Target Var(target_prototype)
Assume all variable arg functions are prototyped
;; FIXME: Does nothing.
diff --git a/gcc/config/rs6000/t-linux64 b/gcc/config/rs6000/t-linux64
index 2a2e7b0cdc0..4c1fae1de83 100644
--- a/gcc/config/rs6000/t-linux64
+++ b/gcc/config/rs6000/t-linux64
@@ -1,8 +1,7 @@
#rs6000/t-linux64
-LIB2FUNCS_EXTRA += tramp.S $(srcdir)/config/rs6000/ppc64-fp.c \
- $(srcdir)/config/rs6000/darwin-ldouble.c
+LIB2FUNCS_EXTRA += $(srcdir)/config/rs6000/ppc64-fp.c
LIB2FUNCS_EXTRA := $(sort $(LIB2FUNCS_EXTRA))
TARGET_LIBGCC2_CFLAGS += -mno-minimal-toc
diff --git a/gcc/config/sh/linux-unwind.h b/gcc/config/sh/linux-unwind.h
index 3a3e9aa392d..0e83f8ce12a 100644
--- a/gcc/config/sh/linux-unwind.h
+++ b/gcc/config/sh/linux-unwind.h
@@ -1,5 +1,5 @@
/* DWARF2 EH unwinding support for SH Linux.
- Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
This file is part of GCC.
@@ -27,7 +27,10 @@ the Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
/* Do code reading to identify a signal frame, and set the frame
- state data appropriately. See unwind-dw2.c for the structs. */
+ state data appropriately. See unwind-dw2.c for the structs.
+ Don't use this at all if inhibit_libc is used. */
+
+#ifndef inhibit_libc
#include <signal.h>
#include <sys/ucontext.h>
@@ -251,3 +254,5 @@ sh_fallback_frame_state (struct _Unwind_Context *context,
return _URC_NO_REASON;
}
#endif /* defined (__SH5__) */
+
+#endif /* inhibit_libc */
diff --git a/gcc/config/sh/sh-protos.h b/gcc/config/sh/sh-protos.h
index 5b971960f2d..caa40a667fa 100644
--- a/gcc/config/sh/sh-protos.h
+++ b/gcc/config/sh/sh-protos.h
@@ -1,6 +1,6 @@
/* Definitions of target machine for GNU compiler for Renesas / SuperH SH.
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2003,
- 2004, 2005, 2006, 2007, 2008
+ 2004, 2005, 2006, 2007, 2008, 2009
Free Software Foundation, Inc.
Contributed by Steve Chamberlain (sac@cygnus.com).
Improved by Jim Wilson (wilson@cygnus.com).
@@ -160,6 +160,7 @@ extern void sh_function_arg_advance (CUMULATIVE_ARGS *, enum machine_mode, tree,
extern int sh_pass_in_reg_p (CUMULATIVE_ARGS *, enum machine_mode, tree);
extern void sh_init_cumulative_args (CUMULATIVE_ARGS *, tree, rtx, tree, signed int, enum machine_mode);
extern bool sh_promote_prototypes (const_tree);
+extern rtx sh_dwarf_register_span (rtx);
extern rtx replace_n_hard_rtx (rtx, rtx *, int , int);
extern int shmedia_cleanup_truncate (rtx *, void *);
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index c8f4c85ee75..4d80354eae5 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -1,6 +1,6 @@
/* Output routines for GCC for Renesas / SuperH SH.
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
- 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+ 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
Contributed by Steve Chamberlain (sac@cygnus.com).
Improved by Jim Wilson (wilson@cygnus.com).
@@ -405,6 +405,9 @@ static int sh2a_function_vector_p (tree);
#undef TARGET_MACHINE_DEPENDENT_REORG
#define TARGET_MACHINE_DEPENDENT_REORG sh_reorg
+#undef TARGET_DWARF_REGISTER_SPAN
+#define TARGET_DWARF_REGISTER_SPAN sh_dwarf_register_span
+
#ifdef HAVE_AS_TLS
#undef TARGET_HAVE_TLS
#define TARGET_HAVE_TLS true
@@ -7426,6 +7429,26 @@ sh_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
return result;
}
+/* 64 bit floating points memory transfers are paired single precision loads
+ or store. So DWARF information needs fixing in little endian (unless
+ PR=SZ=1 in FPSCR). */
+rtx
+sh_dwarf_register_span (rtx reg)
+{
+ unsigned regno = REGNO (reg);
+
+ if (WORDS_BIG_ENDIAN || GET_MODE (reg) != DFmode)
+ return NULL_RTX;
+
+ return
+ gen_rtx_PARALLEL (VOIDmode,
+ gen_rtvec (2,
+ gen_rtx_REG (SFmode,
+ DBX_REGISTER_NUMBER (regno+1)),
+ gen_rtx_REG (SFmode,
+ DBX_REGISTER_NUMBER (regno))));
+}
+
bool
sh_promote_prototypes (const_tree type)
{
diff --git a/gcc/configure b/gcc/configure
index 190dd3c45f7..dcf115c1490 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -22196,7 +22196,7 @@ echo "$as_me:$LINENO: checking linker -Bstatic/-Bdynamic option" >&5
echo $ECHO_N "checking linker -Bstatic/-Bdynamic option... $ECHO_C" >&6
gcc_cv_ld_static_dynamic=no
if test $in_tree_ld = yes ; then
- if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 10; then
+ if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 10 -o "$gcc_cv_gld_major_version" -gt 2; then
gcc_cv_ld_static_dynamic=yes
fi
elif test x$gcc_cv_ld != x; then
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 0b72bcb24d2..5d0221e7823 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2756,7 +2756,7 @@ fi
AC_MSG_CHECKING(linker -Bstatic/-Bdynamic option)
gcc_cv_ld_static_dynamic=no
if test $in_tree_ld = yes ; then
- if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 10; then
+ if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 10 -o "$gcc_cv_gld_major_version" -gt 2; then
gcc_cv_ld_static_dynamic=yes
fi
elif test x$gcc_cv_ld != x; then
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 63d5c0762bb..5cba9d0747a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,12 @@
+2009-04-02 Jason Merrill <jason@redhat.com>
+
+ PR c++/25185
+ * error.c (find_typenames, find_typenames_r): New fns.
+ (dump_function_decl): Call find_typenames.
+ (dump_template_bindings): Print typenames as well.
+ * pt.c (tsubst): Non-static.
+ * cp-tree.h: Declare it.
+
2009-04-02 Dodji Seketeli <dodji@redhat.com>
PR c++/26693
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index f28cfc6353a..849fdc736e4 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4593,6 +4593,7 @@ extern tree most_specialized_instantiation (tree);
extern void print_candidates (tree);
extern void instantiate_pending_templates (int);
extern tree tsubst_default_argument (tree, tree, tree);
+extern tree tsubst (tree, tree, tsubst_flags_t, tree);
extern tree tsubst_copy_and_build (tree, tree, tsubst_flags_t,
tree, bool, bool);
extern tree most_general_template (tree);
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 7d3756e3340..a3d6cc73262 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see
#include "diagnostic.h"
#include "langhooks-def.h"
#include "cxx-pretty-print.h"
+#include "pointer-set.h"
#define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
@@ -74,7 +75,7 @@ static void dump_exception_spec (tree, int);
static void dump_template_argument (tree, int);
static void dump_template_argument_list (tree, int);
static void dump_template_parameter (tree, int);
-static void dump_template_bindings (tree, tree);
+static void dump_template_bindings (tree, tree, VEC(tree,gc) *);
static void dump_scope (tree, int);
static void dump_template_parms (tree, int, int);
@@ -227,9 +228,11 @@ dump_template_parameter (tree parm, int flags)
TREE_VEC. */
static void
-dump_template_bindings (tree parms, tree args)
+dump_template_bindings (tree parms, tree args, VEC(tree,gc)* typenames)
{
int need_comma = 0;
+ int i;
+ tree t;
while (parms)
{
@@ -267,6 +270,17 @@ dump_template_bindings (tree parms, tree args)
parms = TREE_CHAIN (parms);
}
+
+ for (i = 0; VEC_iterate (tree, typenames, i, t); ++i)
+ {
+ if (need_comma)
+ pp_separate_with_comma (cxx_pp);
+ dump_type (t, 0);
+ pp_cxx_whitespace (cxx_pp);
+ pp_equal (cxx_pp);
+ pp_cxx_whitespace (cxx_pp);
+ dump_type (tsubst (t, args, tf_none, NULL_TREE), 0);
+ }
}
/* Dump a human-readable equivalent of TYPE. FLAGS controls the
@@ -1074,6 +1088,51 @@ dump_template_decl (tree t, int flags)
}
}
+/* find_typenames looks through the type of the function template T
+ and returns a VEC containing any TYPENAME_TYPEs it finds. */
+
+struct find_typenames_t
+{
+ struct pointer_set_t *p_set;
+ VEC (tree,gc) *typenames;
+};
+
+static tree
+find_typenames_r (tree *tp, int *walk_subtrees, void *data)
+{
+ struct find_typenames_t *d = (struct find_typenames_t *)data;
+
+ if (TREE_CODE (*tp) == TYPENAME_TYPE)
+ {
+ /* Discard any cv-qualifiers. */
+ tree mv = TYPE_MAIN_VARIANT (*tp);
+ if (mv == *tp || !pointer_set_insert (d->p_set, mv))
+ VEC_safe_push (tree, gc, d->typenames, mv);
+ *walk_subtrees = 0;
+ }
+ /* Search into class template arguments, which cp_walk_subtrees
+ doesn't do. */
+ else if (CLASS_TYPE_P (*tp) && CLASSTYPE_TEMPLATE_INFO (*tp))
+ {
+ cp_walk_tree (&CLASSTYPE_TI_ARGS (*tp), find_typenames_r,
+ data, d->p_set);
+ *walk_subtrees = 0;
+ }
+ return NULL_TREE;
+}
+
+static VEC(tree,gc) *
+find_typenames (tree t)
+{
+ struct find_typenames_t ft;
+ ft.p_set = pointer_set_create ();
+ ft.typenames = NULL;
+ cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t)),
+ find_typenames_r, &ft, ft.p_set);
+ pointer_set_destroy (ft.p_set);
+ return ft.typenames;
+}
+
/* Pretty print a function decl. There are several ways we want to print a
function declaration. The TFF_ bits in FLAGS tells us how to behave.
As error can only apply the '#' flag once to give 0 and 1 for V, there
@@ -1090,6 +1149,7 @@ dump_function_decl (tree t, int flags)
int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS;
int do_outer_scope = ! (flags & TFF_UNQUALIFIED_NAME);
tree exceptions;
+ VEC(tree,gc) *typenames = NULL;
flags &= ~TFF_UNQUALIFIED_NAME;
if (TREE_CODE (t) == TEMPLATE_DECL)
@@ -1110,6 +1170,7 @@ dump_function_decl (tree t, int flags)
{
template_parms = DECL_TEMPLATE_PARMS (tmpl);
t = tmpl;
+ typenames = find_typenames (t);
}
}
@@ -1177,7 +1238,7 @@ dump_function_decl (tree t, int flags)
pp_cxx_left_bracket (cxx_pp);
pp_cxx_identifier (cxx_pp, "with");
pp_cxx_whitespace (cxx_pp);
- dump_template_bindings (template_parms, template_args);
+ dump_template_bindings (template_parms, template_args, typenames);
pp_cxx_right_bracket (cxx_pp);
}
}
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 58a4d3f77ea..8b2fa6e7e17 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -170,7 +170,6 @@ static int eq_local_specializations (const void *, const void *);
static bool dependent_template_arg_p (tree);
static bool any_template_arguments_need_structural_equality_p (tree);
static bool dependent_type_p_r (tree);
-static tree tsubst (tree, tree, tsubst_flags_t, tree);
static tree tsubst_expr (tree, tree, tsubst_flags_t, tree, bool);
static tree tsubst_copy (tree, tree, tsubst_flags_t, tree);
static tree tsubst_pack_expansion (tree, tree, tsubst_flags_t, tree);
@@ -9079,7 +9078,7 @@ tsubst_exception_specification (tree fntype,
This function is used for dealing with types, decls and the like;
for expressions, use tsubst_expr or tsubst_copy. */
-static tree
+tree
tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
{
tree type, r;
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 9500feb1112..e8b5628c0f1 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -2402,7 +2402,7 @@ This attribute is ignored for R8C target.
@item interrupt
@cindex interrupt handler functions
-Use this attribute on the ARM, AVR, CRX, M32C, M32R/D, m68k,
+Use this attribute on the ARM, AVR, CRX, M32C, M32R/D, m68k, MIPS
and Xstormy16 ports to indicate that the specified function is an
interrupt handler. The compiler will generate function entry and exit
sequences suitable for use in an interrupt handler when this attribute
@@ -2425,6 +2425,42 @@ Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF@.
On ARMv7-M the interrupt type is ignored, and the attribute means the function
may be called with a word aligned stack pointer.
+On MIPS targets, you can use the following attributes to modify the behavior
+of an interrupt handler:
+@table @code
+@item use_shadow_register_set
+@cindex @code{use_shadow_register_set} attribute
+Assume that the handler uses a shadow register set, instead of
+the main general-purpose registers.
+
+@item keep_interrupts_masked
+@cindex @code{keep_interrupts_masked} attribute
+Keep interrupts masked for the whole function. Without this attribute,
+GCC tries to reenable interrupts for as much of the function as it can.
+
+@item use_debug_exception_return
+@cindex @code{use_debug_exception_return} attribute
+Return using the @code{deret} instruction. Interrupt handlers that don't
+have this attribute return using @code{eret} instead.
+@end table
+
+You can use any combination of these attributes, as shown below:
+@smallexample
+void __attribute__ ((interrupt)) v0 ();
+void __attribute__ ((interrupt, use_shadow_register_set)) v1 ();
+void __attribute__ ((interrupt, keep_interrupts_masked)) v2 ();
+void __attribute__ ((interrupt, use_debug_exception_return)) v3 ();
+void __attribute__ ((interrupt, use_shadow_register_set,
+ keep_interrupts_masked)) v4 ();
+void __attribute__ ((interrupt, use_shadow_register_set,
+ use_debug_exception_return)) v5 ();
+void __attribute__ ((interrupt, keep_interrupts_masked,
+ use_debug_exception_return)) v6 ();
+void __attribute__ ((interrupt, use_shadow_register_set,
+ keep_interrupts_masked,
+ use_debug_exception_return)) v7 ();
+@end smallexample
+
@item interrupt_handler
@cindex interrupt handler functions on the Blackfin, m68k, H8/300 and SH processors
Use this attribute on the Blackfin, m68k, H8/300, H8/300H, H8S, and SH to
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index a9fb5d986de..5eb977673be 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -315,7 +315,7 @@ Objective-C and Objective-C++ Dialects}.
-print-multi-directory -print-multi-lib @gol
-print-prog-name=@var{program} -print-search-dirs -Q @gol
-print-sysroot -print-sysroot-headers-suffix @gol
--save-temps -time}
+-save-temps -save-temps=cwd -save-temps=obj -time}
@item Optimization Options
@xref{Optimize Options,,Options that Control Optimization}.
@@ -5168,6 +5168,7 @@ And for @var{n} over four, @option{-fsched-verbose} also includes
dependence info.
@item -save-temps
+@itemx -save-temps=cwd
@opindex save-temps
Store the usual ``temporary'' intermediate files permanently; place them
in the current directory and name them based on the source file. Thus,
@@ -5182,6 +5183,39 @@ input source file with the same extension as an intermediate file.
The corresponding intermediate file may be obtained by renaming the
source file before using @option{-save-temps}.
+If you invoke GCC in parallel, compiling several different source
+files that share a common base name in different subdirectories or the
+same source file compiled for multiple output destinations, it is
+likely that the different parallel compilers will interfere with each
+other, and overwrite the temporary files. For instance:
+
+@smallexample
+gcc -save-temps -o outdir1/foo.o indir1/foo.c&
+gcc -save-temps -o outdir2/foo.o indir2/foo.c&
+@end smallexample
+
+may result in @file{foo.i} and @file{foo.o} being written to
+simultaneously by both compilers.
+
+@item -save-temps=obj
+@opindex save-temps=obj
+Store the usual ``temporary'' intermediate files permanently. If the
+@option{-o} option is used, the temporary files are based on the
+object file. If the @option{-o} option is not used, the
+@option{-save-temps=obj} switch behaves like @option{-save-temps}.
+
+For example:
+
+@smallexample
+gcc -save-temps=obj -c foo.c
+gcc -save-temps=obj -c bar.c -o dir/xbar.o
+gcc -save-temps=obj foobar.c -o dir2/yfoobar
+@end smallexample
+
+would create @file{foo.i}, @file{foo.s}, @file{dir/xbar.i},
+@file{dir/xbar.s}, @file{dir2/yfoobar.i}, @file{dir2/yfoobar.s}, and
+@file{dir2/yfoobar.o}.
+
@item -time
@opindex time
Report the CPU time taken by each subprocess in the compilation
diff --git a/gcc/gcc.c b/gcc/gcc.c
index ee953660e5c..c3e6cf5f3e1 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -218,7 +218,15 @@ static const char *target_sysroot_hdrs_suffix = 0;
/* Nonzero means write "temp" files in source directory
and use the source file's name in them, and don't delete them. */
-static int save_temps_flag;
+static enum save_temps {
+ SAVE_TEMPS_NONE, /* no -save-temps */
+ SAVE_TEMPS_CWD, /* -save-temps in current directory */
+ SAVE_TEMPS_OBJ /* -save-temps in object directory */
+} save_temps_flag;
+
+/* Output file to use to get the object directory for -save-temps=obj */
+static char *save_temps_prefix = 0;
+static size_t save_temps_length = 0;
/* Nonzero means pass multiple source files to the compiler at one time. */
@@ -393,7 +401,8 @@ or with constant text in a single argument.
%i substitute the name of the input file being processed.
%b substitute the basename of the input file being processed.
This is the substring up to (and not including) the last period
- and not including the directory.
+ and not including the directory unless -save-temps was specified
+ to put temporaries in a different location.
%B same as %b, but include the file suffix (text after the last period).
%gSUFFIX
substitute a file name that has suffix SUFFIX and is chosen
@@ -817,7 +826,7 @@ static const char *cpp_unique_options =
static const char *cpp_options =
"%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\
%{f*} %{g*:%{!g0:%{g*} %{!fno-working-directory:-fworking-directory}}} %{O*}\
- %{undef} %{save-temps:-fpch-preprocess}";
+ %{undef} %{save-temps*:-fpch-preprocess}";
/* This contains cpp options which are not passed when the preprocessor
output will be used by another program. */
@@ -996,17 +1005,17 @@ static const struct compiler default_compilers[] =
%{traditional|ftraditional:\
%eGNU C no longer supports -traditional without -E}\
%{!combine:\
- %{save-temps|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
- %(cpp_options) -o %{save-temps:%b.i} %{!save-temps:%g.i} \n\
- cc1 -fpreprocessed %{save-temps:%b.i} %{!save-temps:%g.i} \
+ %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
+ %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
+ cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
%(cc1_options)}\
- %{!save-temps:%{!traditional-cpp:%{!no-integrated-cpp:\
+ %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
cc1 %(cpp_unique_options) %(cc1_options)}}}\
%{!fsyntax-only:%(invoke_as)}} \
%{combine:\
- %{save-temps|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
- %(cpp_options) -o %{save-temps:%b.i} %{!save-temps:%g.i}}\
- %{!save-temps:%{!traditional-cpp:%{!no-integrated-cpp:\
+ %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
+ %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i}}\
+ %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
cc1 %(cpp_unique_options) %(cc1_options)}}\
%{!fsyntax-only:%(invoke_as)}}}}}}", 0, 1, 1},
{"-",
@@ -1018,13 +1027,13 @@ static const struct compiler default_compilers[] =
external preprocessor if -save-temps is given. */
"%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
%{!E:%{!M:%{!MM:\
- %{save-temps|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
- %(cpp_options) -o %{save-temps:%b.i} %{!save-temps:%g.i} \n\
- cc1 -fpreprocessed %{save-temps:%b.i} %{!save-temps:%g.i} \
+ %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
+ %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
+ cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
%(cc1_options)\
-o %g.s %{!o*:--output-pch=%i.gch}\
%W{o*:--output-pch=%*}%V}\
- %{!save-temps:%{!traditional-cpp:%{!no-integrated-cpp:\
+ %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
cc1 %(cpp_unique_options) %(cc1_options)\
-o %g.s %{!o*:--output-pch=%i.gch}\
%W{o*:--output-pch=%*}%V}}}}}}", 0, 0, 0},
@@ -3255,6 +3264,7 @@ display_help (void)
fputs (_(" -Xlinker <arg> Pass <arg> on to the linker\n"), stdout);
fputs (_(" -combine Pass multiple source files to compiler at once\n"), stdout);
fputs (_(" -save-temps Do not delete intermediate files\n"), stdout);
+ fputs (_(" -save-temps=<arg> Do not delete intermediate files\n"), stdout);
fputs (_(" -pipe Use pipes rather than intermediate files\n"), stdout);
fputs (_(" -time Time the execution of each subprocess\n"), stdout);
fputs (_(" -specs=<file> Override built-in specs with the contents of <file>\n"), stdout);
@@ -3789,8 +3799,19 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
n_infiles++;
else if (strcmp (argv[i], "-save-temps") == 0)
{
- save_temps_flag = 1;
+ save_temps_flag = SAVE_TEMPS_CWD;
+ n_switches++;
+ }
+ else if (strncmp (argv[i], "-save-temps=", 12) == 0)
+ {
n_switches++;
+ if (strcmp (argv[i]+12, "cwd") == 0)
+ save_temps_flag = SAVE_TEMPS_CWD;
+ else if (strcmp (argv[i]+12, "obj") == 0
+ || strcmp (argv[i]+12, "object") == 0)
+ save_temps_flag = SAVE_TEMPS_OBJ;
+ else
+ fatal ("'%s' is an unknown -save-temps option", argv[i]);
}
else if (strcmp (argv[i], "-combine") == 0)
{
@@ -3965,6 +3986,8 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
else
argv[i] = convert_filename (argv[i], ! have_c, 0);
#endif
+ /* Save the output name in case -save-temps=obj was used. */
+ save_temps_prefix = xstrdup ((p[1] == 0) ? argv[i + 1] : argv[i] + 1);
goto normal_switch;
default:
@@ -4022,6 +4045,25 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
}
}
+ /* If -save-temps=obj and -o name, create the prefix to use for %b.
+ Otherwise just make -save-temps=obj the same as -save-temps=cwd. */
+ if (save_temps_flag == SAVE_TEMPS_OBJ && save_temps_prefix != NULL)
+ {
+ save_temps_length = strlen (save_temps_prefix);
+ temp = strrchr (lbasename (save_temps_prefix), '.');
+ if (temp)
+ {
+ save_temps_length -= strlen (temp);
+ save_temps_prefix[save_temps_length] = '\0';
+ }
+
+ }
+ else if (save_temps_prefix != NULL)
+ {
+ free (save_temps_prefix);
+ save_temps_prefix = NULL;
+ }
+
if (save_temps_flag && use_pipes)
{
/* -save-temps overrides -pipe, so that temp files are produced */
@@ -4776,12 +4818,18 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
fatal ("spec '%s' invalid", spec);
case 'b':
- obstack_grow (&obstack, input_basename, basename_length);
+ if (save_temps_length)
+ obstack_grow (&obstack, save_temps_prefix, save_temps_length);
+ else
+ obstack_grow (&obstack, input_basename, basename_length);
arg_going = 1;
break;
case 'B':
- obstack_grow (&obstack, input_basename, suffixed_basename_length);
+ if (save_temps_length)
+ obstack_grow (&obstack, save_temps_prefix, save_temps_length);
+ else
+ obstack_grow (&obstack, input_basename, suffixed_basename_length);
arg_going = 1;
break;
@@ -4927,6 +4975,26 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
suffix_length += strlen (TARGET_OBJECT_SUFFIX);
}
+ /* If -save-temps=obj and -o were specified, use that for the
+ temp file. */
+ if (save_temps_length)
+ {
+ char *tmp;
+ temp_filename_length
+ = save_temps_length + suffix_length + 1;
+ tmp = (char *) alloca (temp_filename_length);
+ memcpy (tmp, save_temps_prefix, save_temps_length);
+ memcpy (tmp + save_temps_length, suffix, suffix_length);
+ tmp[save_temps_length + suffix_length] = '\0';
+ temp_filename = save_string (tmp,
+ temp_filename_length + 1);
+ obstack_grow (&obstack, temp_filename,
+ temp_filename_length);
+ arg_going = 1;
+ delete_this_arg = 0;
+ break;
+ }
+
/* If the input_filename has the same suffix specified
for the %g, %u, or %U, and -save-temps is specified,
we could end up using that file as an intermediate
@@ -4938,13 +5006,13 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
if (save_temps_flag)
{
char *tmp;
-
- temp_filename_length = basename_length + suffix_length;
- tmp = (char *) alloca (temp_filename_length + 1);
- strncpy (tmp, input_basename, basename_length);
- strncpy (tmp + basename_length, suffix, suffix_length);
- tmp[temp_filename_length] = '\0';
+ temp_filename_length = basename_length + suffix_length + 1;
+ tmp = (char *) alloca (temp_filename_length);
+ memcpy (tmp, input_basename, basename_length);
+ memcpy (tmp + basename_length, suffix, suffix_length);
+ tmp[basename_length + suffix_length] = '\0';
temp_filename = tmp;
+
if (strcmp (temp_filename, input_filename) != 0)
{
#ifndef HOST_LACKS_INODE_NUMBERS
@@ -6165,16 +6233,7 @@ set_input (const char *filename)
input_filename = filename;
input_filename_length = strlen (input_filename);
-
- input_basename = input_filename;
-#ifdef HAVE_DOS_BASED_FILE_SYSTEM
- /* Skip drive name so 'x:foo' is handled properly. */
- if (input_basename[1] == ':')
- input_basename += 2;
-#endif
- for (p = input_basename; *p; p++)
- if (IS_DIR_SEPARATOR (*p))
- input_basename = p + 1;
+ input_basename = lbasename (input_filename);
/* Find a suffix starting with the last period,
and set basename_length to exclude that suffix. */
diff --git a/gcc/passes.c b/gcc/passes.c
index 92078418c50..f19b8dda166 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -590,7 +590,6 @@ init_optimization_passes (void)
/* Initial scalar cleanups before alias computation.
They ensure memory accesses are not indirect wherever possible. */
NEXT_PASS (pass_strip_predict_hints);
- NEXT_PASS (pass_cleanup_eh);
NEXT_PASS (pass_update_address_taken);
NEXT_PASS (pass_rename_ssa_copies);
NEXT_PASS (pass_complete_unrolli);
@@ -688,7 +687,6 @@ init_optimization_passes (void)
NEXT_PASS (pass_phi_only_cprop);
NEXT_PASS (pass_cd_dce);
NEXT_PASS (pass_tracer);
- NEXT_PASS (pass_cleanup_eh);
/* FIXME: If DCE is not run before checking for uninitialized uses,
we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
diff --git a/gcc/reload1.c b/gcc/reload1.c
index fcf0bd3fc4d..180c394b421 100644
--- a/gcc/reload1.c
+++ b/gcc/reload1.c
@@ -4086,26 +4086,17 @@ static void
fixup_eh_region_note (rtx insn, rtx prev, rtx next)
{
rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
- unsigned int trap_count;
rtx i;
if (note == NULL)
return;
- if (may_trap_p (PATTERN (insn)))
- trap_count = 1;
- else
- {
- remove_note (insn, note);
- trap_count = 0;
- }
+ if (! may_trap_p (PATTERN (insn)))
+ remove_note (insn, note);
for (i = NEXT_INSN (prev); i != next; i = NEXT_INSN (i))
if (INSN_P (i) && i != insn && may_trap_p (PATTERN (i)))
- {
- trap_count++;
- add_reg_note (i, REG_EH_REGION, XEXP (note, 0));
- }
+ add_reg_note (i, REG_EH_REGION, XEXP (note, 0));
}
/* Reload pseudo-registers into hard regs around each insn as needed.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3081d43219a..a73f8af3ae6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,28 @@
+2009-04-02 Chao-ying Fu <fu@mips.com>
+
+ * gcc.target/mips/interrupt_handler.c: New test.
+
+2009-04-02 David Ayers <ayers@fsfe.org>
+
+ PR objc/18456
+ * objc.dg/bad-receiver-type-2.m: New test contributed by
+ Alexander Mamberg.
+
+2009-04-02 Jason Merrill <jason@redhat.com>
+
+ PR c++/25185
+ * g++.dg/template/error38.C: New test.
+
+2009-04-02 Janis Johnson <janis187@us.ibm.com>
+
+ PR tree-optimization/31677
+ * gcc.dg/memcpy-1.c: Add compiler option.
+
+2009-04-02 Ira Rosen <irar@il.ibm.com>
+
+ PR tree-optimization/39595
+ * gfortran.dg/vect/O3-pr39595.f: New test.
+
2009-04-02 Dodji Seketeli <dodji@redhat.com>
PR c++/26693
diff --git a/gcc/testsuite/g++.dg/template/error38.C b/gcc/testsuite/g++.dg/template/error38.C
new file mode 100644
index 00000000000..a444b1a233f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/error38.C
@@ -0,0 +1,19 @@
+// Testcase for printing typename bindings as well as template args
+// in diagnostics (PR c++/25185)
+
+template <class T>
+struct A {
+ typename T::type f(); // { dg-message "typename T::type = void*" }
+ void f(int i = 0); // { dg-message "" }
+};
+
+struct B
+{
+ typedef void* type;
+};
+
+int main()
+{
+ A<B> a;
+ a.f(); // { dg-error "" }
+}
diff --git a/gcc/testsuite/gcc.dg/memcpy-1.c b/gcc/testsuite/gcc.dg/memcpy-1.c
index 2b11098b286..cc602423793 100644
--- a/gcc/testsuite/gcc.dg/memcpy-1.c
+++ b/gcc/testsuite/gcc.dg/memcpy-1.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-options "-O2 -fdump-tree-optimized --param sra-max-structure-size=32" } */
/* PR36598 AVR fail maybe due to cost metrics */
/* { dg-final { scan-tree-dump-times "nasty_local" 0 "optimized" { xfail { "avr-*-*" } } } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.target/mips/interrupt_handler.c b/gcc/testsuite/gcc.target/mips/interrupt_handler.c
new file mode 100644
index 00000000000..1cf891829f7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/mips/interrupt_handler.c
@@ -0,0 +1,23 @@
+/* Test attributes for interrupt handlers */
+/* { dg-do compile } */
+/* { dg-options "-mips32r2 -msoft-float" } */
+
+void f () { }
+
+void __attribute__ ((interrupt)) v0 () { }
+void __attribute__ ((interrupt, use_shadow_register_set)) v1 () { }
+void __attribute__ ((interrupt, keep_interrupts_masked)) v2 () { }
+void __attribute__ ((interrupt, use_debug_exception_return)) v3 () { }
+void __attribute__ ((interrupt, use_shadow_register_set, keep_interrupts_masked)) v4 () { }
+void __attribute__ ((interrupt, use_shadow_register_set, use_debug_exception_return)) v5 () { }
+void __attribute__ ((interrupt, keep_interrupts_masked, use_debug_exception_return)) v6 () { }
+void __attribute__ ((interrupt, use_shadow_register_set, keep_interrupts_masked, use_debug_exception_return)) v7 () { }
+
+void __attribute__ ((interrupt)) w0 () { t(); }
+void __attribute__ ((interrupt, use_shadow_register_set)) w1 () { t(); }
+void __attribute__ ((interrupt, keep_interrupts_masked)) w2 () { t(); }
+void __attribute__ ((interrupt, use_debug_exception_return)) w3 () { t(); }
+void __attribute__ ((interrupt, use_shadow_register_set, keep_interrupts_masked)) w4 () { t(); }
+void __attribute__ ((interrupt, use_shadow_register_set, use_debug_exception_return)) w5 () { t(); }
+void __attribute__ ((interrupt, keep_interrupts_masked, use_debug_exception_return)) w6 () { t(); }
+void __attribute__ ((interrupt, use_shadow_register_set, keep_interrupts_masked, use_debug_exception_return)) w7 () { t(); }
diff --git a/gcc/testsuite/gfortran.dg/vect/O3-pr39595.f b/gcc/testsuite/gfortran.dg/vect/O3-pr39595.f
new file mode 100644
index 00000000000..021d35b90ea
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/vect/O3-pr39595.f
@@ -0,0 +1,17 @@
+! { dg-do compile }
+ subroutine foo(a,c,i,m)
+ real a(4,*),b(3,64),c(3,200),d(64)
+ integer*8 i,j,k,l,m
+ do j=1,m,64
+ do k=1,m-j+1
+ d(k)=a(4,j-1+k)
+ do l=1,3
+ b(l,k)=c(l,i)+a(l,j-1+k)
+ end do
+ end do
+ call bar(b,d,i)
+ end do
+ end
+
+! { dg-final { cleanup-tree-dump "vect" } }
+
diff --git a/gcc/testsuite/objc.dg/bad-receiver-type-2.m b/gcc/testsuite/objc.dg/bad-receiver-type-2.m
new file mode 100644
index 00000000000..eca8400d503
--- /dev/null
+++ b/gcc/testsuite/objc.dg/bad-receiver-type-2.m
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+/* Contributed by Alexander Malmberg: PR18456 */
+
+@interface Foo
+-(void) foo;
+@end
+
+void *ip;
+
+void (*func1)(void);
+
+struct
+{
+ int a:2;
+} struct1,struct2[2];
+
+union
+{
+ int a:2;
+} union1,union2[2];
+
+Foo **f;
+
+int main(int argc,char **argv)
+{
+ [(struct {int a;} *)ip foo]; /* { dg-warning "invalid receiver type" } */
+ [func1 foo]; /* { dg-warning "invalid receiver type" } */
+ [struct1.a foo]; /* { dg-warning "invalid receiver type" } */
+ /* { dg-warning "cast to pointer from integer" "" { target *-*-* } 28 } */
+ [union1.a foo]; /* { dg-warning "invalid receiver type" } */
+ /* { dg-warning "cast to pointer from integer" "" { target *-*-* } 30 } */
+ [struct1 foo]; /* { dg-warning "invalid receiver type" } */
+ /* { dg-error "cannot convert" "" { target *-*-* } 32 } */
+ [union1 foo]; /* { dg-warning "invalid receiver type" } */
+ /* { dg-error "cannot convert" "" { target *-*-* } 34 } */
+ [struct2 foo]; /* { dg-warning "invalid receiver type" } */
+ /* { dg-error "cannot convert" "" { target *-*-* } 36 } */
+ [union2 foo]; /* { dg-warning "invalid receiver type" } */
+ /* { dg-error "cannot convert" "" { target *-*-* } 38 } */
+ [f foo]; /* { dg-warning "invalid receiver type" } */
+}
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 8ead071a3a7..058438dc5e9 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -466,6 +466,22 @@ vect_build_slp_tree (loop_vec_info loop_vinfo, slp_tree *node,
return false;
}
+
+ /* Check that the size of interleaved loads group is not
+ greater than the SLP group size. */
+ if (DR_GROUP_SIZE (vinfo_for_stmt (stmt))
+ > ncopies * group_size)
+ {
+ if (vect_print_dump_info (REPORT_SLP))
+ {
+ fprintf (vect_dump, "Build SLP failed: the number of "
+ "interleaved loads is greater than"
+ " the SLP group size ");
+ print_gimple_stmt (vect_dump, stmt, 0, TDF_SLIM);
+ }
+
+ return false;
+ }
first_load = DR_GROUP_FIRST_DR (vinfo_for_stmt (stmt));
diff --git a/gcc/tree.h b/gcc/tree.h
index 945c7b5b69f..b191d43d046 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4839,6 +4839,7 @@ extern tree build_string_literal (int, const char *);
extern bool validate_arglist (const_tree, ...);
extern rtx builtin_memset_read_str (void *, HOST_WIDE_INT, enum machine_mode);
extern int get_pointer_alignment (tree, unsigned int);
+extern bool is_builtin_name(const char*);
extern int get_object_alignment (tree, unsigned int, unsigned int);
extern tree fold_call_stmt (gimple, bool);
extern tree gimple_fold_builtin_snprintf_chk (gimple, tree, enum built_in_function);
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 16d87824aff..4e414442e54 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -2256,7 +2256,7 @@ incorporeal_function_p (tree decl)
return true;
name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
- if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
+ if (is_builtin_name (name))
return true;
}
return false;
diff --git a/gcc/varpool.c b/gcc/varpool.c
index 8c1259b14ec..12cdad90e28 100644
--- a/gcc/varpool.c
+++ b/gcc/varpool.c
@@ -164,6 +164,14 @@ dump_varpool (FILE *f)
dump_varpool_node (f, node);
}
+/* Dump the variable pool to stderr. */
+
+void
+debug_varpool (void)
+{
+ dump_varpool (stderr);
+}
+
/* Given an assembler name, lookup node. */
struct varpool_node *
varpool_node_for_asm (tree asmname)
diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog
index d9d2b3d9834..ebabcfe2b64 100644
--- a/libgcc/ChangeLog
+++ b/libgcc/ChangeLog
@@ -1,3 +1,7 @@
+2009-04-03 Alan Modra <amodra@bigpond.net.au>
+
+ * config.host (powerpc-*-linux*altivec*, powerpc-*-linux*spe): Delete.
+
2009-03-28 Joseph Myers <joseph@codesourcery.com>
* config.host (arm-*-coff*, armel-*-coff*, arm-semi-aof,
diff --git a/libgcc/config.host b/libgcc/config.host
index ad2ca4194e6..2374ead9350 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -448,12 +448,6 @@ powerpc-*-eabi*)
;;
powerpc-*-rtems*)
;;
-powerpc-*-linux*altivec*)
- tmake_file="${tmake_file} rs6000/t-ppccomm rs6000/t-ldbl128"
- ;;
-powerpc-*-linux*spe*)
- tmake_file="${tmake_file} rs6000/t-ppccomm rs6000/t-ldbl128 t-softfp"
- ;;
powerpc-*-linux*)
tmake_file="${tmake_file} rs6000/t-ppccomm rs6000/t-ldbl128 t-softfp"
;;
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 61b2c0594a2..23954fbe883 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,6 +1,324 @@
+2009-04-02 Benjamin Kosnik <bkoz@redhat.com>
+
+ * testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc:
+ Change to mersenne_twister_engine, add same defaults as
+ mersenne_twister_engine/cons/default.cc.
+ * testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc: Same.
+
+ * include/bits/random.tcc (seed_seq::seed_seq): Uglify parameter
+ to __il.
+ * include/bits/random.h (mersenne_twister_engine): Qualify
+ _ShiftMin1 with namespace __detail.
+ (__detail::_ShiftMin1): Use __gnu_cxx::__numeric_traits::max until
+ constexpr std::numeric_limits::max() can be used.
+ (mersenne_twister_engine): Split apart static asserts into one
+ assert per message. Temporarily disable the last three.
+
+2009-04-02 Edward Smith-Rowland <3dw4rd@verizon.net>
+
+ * include/Makefile.am: Update to N2836. Modified for new random headers.
+ * include/Makefile.in: Ditto.
+ * include/tr1_impl/random: Moved to tr1/random.h
+ * include/tr1_impl/random.tcc: Moved to tr1
+ * include/tr1/random: Just point to moved tr1 random headers.
+ * include/tr1/random.tcc: Moved from tr1_impl.
+ * include/tr1/random.h: Moved from tr1_impl/random.
+ * include/std/random: Modified to point to std random headers.
+ * include/bits/random.tcc: New implementation of std random facilities.
+ * include/bits/random.h: Ditto.
+ * testsuite/26_numerics/headers/random/std_c++0x_neg.cc: Changed.
+ * testsuite/26_numerics/random/linear_congruential_engine/cons/
+ seed1.cc: New.
+ * testsuite/26_numerics/random/linear_congruential_engine/cons/
+ seed2.cc: New.
+ * testsuite/26_numerics/random/linear_congruential_engine/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/linear_congruential_engine/requirements/
+ non_uint_neg.cc: New.
+ * testsuite/26_numerics/random/linear_congruential_engine/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/linear_congruential_engine/operators/
+ equal.cc: New.
+ * testsuite/26_numerics/random/linear_congruential_engine/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/mersenne_twister_engine/cons/
+ seed1.cc: New.
+ * testsuite/26_numerics/random/mersenne_twister_engine/cons/
+ seed2.cc: New.
+ * testsuite/26_numerics/random/mersenne_twister_engine/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/mersenne_twister_engine/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/mersenne_twister_engine/operators/
+ equal.cc: New.
+ * testsuite/26_numerics/random/mersenne_twister_engine/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/subtract_with_carry_engine/cons/
+ seed1.cc: New.
+ * testsuite/26_numerics/random/subtract_with_carry_engine/cons/
+ seed2.cc: New.
+ * testsuite/26_numerics/random/subtract_with_carry_engine/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/subtract_with_carry_engine/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/subtract_with_carry_engine/operators/
+ equal.cc: New.
+ * testsuite/26_numerics/random/subtract_with_carry_engine/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/discard_block_engine/cons/
+ base_move.cc: New.
+ * testsuite/26_numerics/random/discard_block_engine/cons/
+ seed1.cc: New.
+ * testsuite/26_numerics/random/discard_block_engine/cons/
+ seed2.cc: New.
+ * testsuite/26_numerics/random/discard_block_engine/cons/
+ base_copy.cc: New.
+ * testsuite/26_numerics/random/discard_block_engine/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/discard_block_engine/cons/
+ seed_seq.cc: New.
+ * testsuite/26_numerics/random/discard_block_engine/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/discard_block_engine/operators/
+ equal.cc: New.
+ * testsuite/26_numerics/random/discard_block_engine/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/independent_bits_engine/cons/
+ base_move.cc: New.
+ * testsuite/26_numerics/random/independent_bits_engine/cons/
+ seed1.cc: New.
+ * testsuite/26_numerics/random/independent_bits_engine/cons/
+ seed2.cc: New.
+ * testsuite/26_numerics/random/independent_bits_engine/cons/
+ base_copy.cc: New.
+ * testsuite/26_numerics/random/independent_bits_engine/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/independent_bits_engine/cons/
+ seed_seq.cc: New.
+ * testsuite/26_numerics/random/independent_bits_engine/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/independent_bits_engine/operators/
+ equal.cc: New.
+ * testsuite/26_numerics/random/independent_bits_engine/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/shuffle_order_engine/cons/
+ base_move.cc: New.
+ * testsuite/26_numerics/random/shuffle_order_engine/cons/
+ seed1.cc: New.
+ * testsuite/26_numerics/random/shuffle_order_engine/cons/
+ seed2.cc: New.
+ * testsuite/26_numerics/random/shuffle_order_engine/cons/
+ base_copy.cc: New.
+ * testsuite/26_numerics/random/shuffle_order_engine/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/shuffle_order_engine/cons/
+ seed_seq.cc: New.
+ * testsuite/26_numerics/random/shuffle_order_engine/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/shuffle_order_engine/operators/
+ equal.cc: New.
+ * testsuite/26_numerics/random/shuffle_order_engine/operators/
+ serialize.cc
+ * testsuite/26_numerics/random/mt19937.cc: New.
+ * testsuite/26_numerics/random/mt19937_64.cc: New.
+ * testsuite/26_numerics/random/minstd_rand.cc: New.
+ * testsuite/26_numerics/random/minstd_rand0.cc: New.
+ * testsuite/26_numerics/random/ranlux24_base.cc: New.
+ * testsuite/26_numerics/random/ranlux48_base.cc: New.
+ * testsuite/26_numerics/random/ranlux24.cc: New.
+ * testsuite/26_numerics/random/ranlux48.cc: New.
+ * testsuite/26_numerics/random/knuth_b.cc: New.
+ * testsuite/26_numerics/random/default_random_engine.cc: New.
+ * testsuite/26_numerics/random/chi_squared_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/chi_squared_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/chi_squared_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/chi_squared_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/normal_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/normal_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/normal_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/normal_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/seed_seq/cons/range.cc: New.
+ * testsuite/26_numerics/random/seed_seq/cons/default.cc: New.
+ * testsuite/26_numerics/random/seed_seq/requirements/typedefs.cc: New.
+ * testsuite/26_numerics/random/uniform_int_distribution/cons/
+ parms_neg.cc: New.
+ * testsuite/26_numerics/random/uniform_int_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/uniform_int_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/uniform_int_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/uniform_int_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/uniform_real_distribution/cons/
+ parms_neg.cc: New.
+ * testsuite/26_numerics/random/uniform_real_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/uniform_real_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/uniform_real_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/uniform_real_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/poisson_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/poisson_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/poisson_distribution/requirements/
+ typedefs.cc
+ * testsuite/26_numerics/random/poisson_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/bernoulli_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/bernoulli_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/bernoulli_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/bernoulli_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/discrete_distribution/cons/
+ range.cc: New.
+ * testsuite/26_numerics/random/discrete_distribution/cons/
+ initlist.cc: New.
+ * testsuite/26_numerics/random/discrete_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/discrete_distribution/cons/
+ num_xbound_fun.cc: New.
+ * testsuite/26_numerics/random/discrete_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/discrete_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/weibull_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/weibull_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/weibull_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/weibull_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/negative_binomial_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/negative_binomial_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/negative_binomial_distribution/
+ requirements/typedefs.cc: New.
+ * testsuite/26_numerics/random/negative_binomial_distribution/
+ operators/serialize.cc: New.
+ * testsuite/26_numerics/random/cauchy_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/cauchy_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/cauchy_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/cauchy_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/gamma_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/gamma_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/gamma_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/gamma_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/fisher_f_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/fisher_f_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/fisher_f_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/fisher_f_distribution/operators/
+ serialize.cc: New.
+
+ * testsuite/26_numerics/random/exponential_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/exponential_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/exponential_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/exponential_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/lognormal_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/lognormal_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/lognormal_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/lognormal_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/binomial_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/binomial_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/binomial_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/binomial_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/random_device/cons/
+ token.cc: New.
+ * testsuite/26_numerics/random/random_device/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/random_device/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/extreme_value_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/extreme_value_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/extreme_value_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/extreme_value_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/piecewise_linear_distribution/cons/
+ range.cc: New.
+ * testsuite/26_numerics/random/piecewise_linear_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/piecewise_linear_distribution/cons/
+ num_xbound_fun.cc: New.
+ * testsuite/26_numerics/random/piecewise_linear_distribution/cons/
+ initlist_fun.cc: New.
+ * testsuite/26_numerics/random/piecewise_linear_distribution/
+ requirements/typedefs.cc: New.
+ * testsuite/26_numerics/random/piecewise_linear_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/student_t_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/student_t_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/student_t_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/student_t_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/geometric_distribution/cons/
+ parms.cc: New.
+ * testsuite/26_numerics/random/geometric_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/geometric_distribution/requirements/
+ typedefs.cc: New.
+ * testsuite/26_numerics/random/geometric_distribution/operators/
+ serialize.cc: New.
+ * testsuite/26_numerics/random/piecewise_constant_distribution/cons/
+ range.cc: New.
+ * testsuite/26_numerics/random/piecewise_constant_distribution/cons/
+ default.cc: New.
+ * testsuite/26_numerics/random/piecewise_constant_distribution/cons/
+ num_xbound_fun.cc: New.
+ * testsuite/26_numerics/random/piecewise_constant_distribution/cons/
+ initlist_fun.cc: New.
+ * testsuite/26_numerics/random/piecewise_constant_distribution/
+ requirements/typedefs.cc: New.
+ * testsuite/26_numerics/random/piecewise_constant_distribution/
+ operators/serialize.cc: New.
+
2009-04-02 Dodji Seketeli <dodji@redhat.com>
- * include/ext/bitmap_allocator.h: the typedefs should be made public
+ * include/ext/bitmap_allocator.h: The typedefs should be made public
if we want them to be accessible. This has been revealed by the patch
that fixes PR c++/26693 in g++.
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 5205e704d92..6b481ce3e07 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -116,6 +116,8 @@ bits_headers = \
${bits_srcdir}/ostream.tcc \
${bits_srcdir}/ostream_insert.h \
${bits_srcdir}/postypes.h \
+ ${bits_srcdir}/random.h \
+ ${bits_srcdir}/random.tcc \
${bits_srcdir}/stream_iterator.h \
${bits_srcdir}/streambuf_iterator.h \
${bits_srcdir}/shared_ptr.h \
@@ -570,6 +572,8 @@ tr1_headers = \
${tr1_srcdir}/poly_laguerre.tcc \
${tr1_srcdir}/legendre_function.tcc \
${tr1_srcdir}/random \
+ ${tr1_srcdir}/random.h \
+ ${tr1_srcdir}/random.tcc \
${tr1_srcdir}/regex \
${tr1_srcdir}/riemann_zeta.tcc \
${tr1_srcdir}/shared_ptr.h \
@@ -608,8 +612,6 @@ tr1_impl_headers = \
${tr1_impl_srcdir}/functional_hash.h \
${tr1_impl_srcdir}/hashtable \
${tr1_impl_srcdir}/hashtable_policy.h \
- ${tr1_impl_srcdir}/random \
- ${tr1_impl_srcdir}/random.tcc \
${tr1_impl_srcdir}/regex \
${tr1_impl_srcdir}/type_traits \
${tr1_impl_srcdir}/unordered_map \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index ae85f7eabe8..c1ad2d3dd57 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -381,6 +381,8 @@ bits_headers = \
${bits_srcdir}/ostream.tcc \
${bits_srcdir}/ostream_insert.h \
${bits_srcdir}/postypes.h \
+ ${bits_srcdir}/random.h \
+ ${bits_srcdir}/random.tcc \
${bits_srcdir}/stream_iterator.h \
${bits_srcdir}/streambuf_iterator.h \
${bits_srcdir}/shared_ptr.h \
@@ -833,6 +835,8 @@ tr1_headers = \
${tr1_srcdir}/poly_laguerre.tcc \
${tr1_srcdir}/legendre_function.tcc \
${tr1_srcdir}/random \
+ ${tr1_srcdir}/random.h \
+ ${tr1_srcdir}/random.tcc \
${tr1_srcdir}/regex \
${tr1_srcdir}/riemann_zeta.tcc \
${tr1_srcdir}/shared_ptr.h \
@@ -870,8 +874,6 @@ tr1_impl_headers = \
${tr1_impl_srcdir}/functional_hash.h \
${tr1_impl_srcdir}/hashtable \
${tr1_impl_srcdir}/hashtable_policy.h \
- ${tr1_impl_srcdir}/random \
- ${tr1_impl_srcdir}/random.tcc \
${tr1_impl_srcdir}/regex \
${tr1_impl_srcdir}/type_traits \
${tr1_impl_srcdir}/unordered_map \
diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
new file mode 100644
index 00000000000..ad64a90a681
--- /dev/null
+++ b/libstdc++-v3/include/bits/random.h
@@ -0,0 +1,4940 @@
+// random number generation -*- C++ -*-
+
+// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/**
+ * @file bits/random.h
+ * This is an internal header file, included by other library headers.
+ * You should not attempt to use it directly.
+ */
+
+#include <vector>
+
+namespace std
+{
+
+ // [26.4] Random number generation
+
+ /**
+ * @addtogroup std_random Random Number Generation
+ * A facility for generating random numbers on selected distributions.
+ * @{
+ */
+
+ /**
+ * @brief A function template for converting the output of a (integral)
+ * uniform random number generator to a floatng point result in the range
+ * [0-1).
+ */
+ template<typename _RealType, size_t __bits,
+ typename _UniformRandomNumberGenerator>
+ _RealType
+ generate_canonical(_UniformRandomNumberGenerator& __g);
+
+ class seed_seq;
+
+ /*
+ * Implementation-space details.
+ */
+ namespace __detail
+ {
+ template<typename _UIntType, size_t __w,
+ bool = __w < static_cast<size_t>(std::numeric_limits<_UIntType>::digits)>
+ struct _Shift
+ { static const _UIntType __value = 0; };
+
+ template<typename _UIntType, size_t __w>
+ struct _Shift<_UIntType, __w, true>
+ { static const _UIntType __value = _UIntType(1) << __w; };
+
+ // XXX need constexpr
+ template<typename _UIntType, size_t __w,
+ bool = __w <static_cast<size_t>(std::numeric_limits<_UIntType>::digits)>
+ struct _ShiftMin1
+ { static const _UIntType __value = __gnu_cxx::__numeric_traits<_UIntType>::max; };
+
+ template<typename _UIntType, size_t __w>
+ struct _ShiftMin1<_UIntType, __w, true>
+ { static const _UIntType __value = _UIntType(1) << __w - _UIntType(1); };
+
+ template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool>
+ struct _Mod;
+
+ // Dispatch based on modulus value to prevent divide-by-zero compile-time
+ // errors when m == 0.
+ template<typename _Tp, _Tp __a, _Tp __c, _Tp __m>
+ inline _Tp
+ __mod(_Tp __x)
+ { return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); }
+
+ typedef __gnu_cxx::__conditional_type<(sizeof(unsigned) == 4),
+ unsigned, unsigned long>::__type _UInt32Type;
+
+ /*
+ * An adaptor class for converting the output of any Generator into
+ * the input for a specific Distribution.
+ */
+ template<typename _Engine, typename _DInputType>
+ struct _Adaptor
+ {
+
+ public:
+ _Adaptor(_Engine& __g)
+ : _M_g(__g) { }
+
+ _DInputType
+ min() const
+ {
+ if (is_integral<_DInputType>::value)
+ return _M_g.min();
+ else
+ return _DInputType(0);
+ }
+
+ _DInputType
+ max() const
+ {
+ if (is_integral<_DInputType>::value)
+ return _M_g.max();
+ else
+ return _DInputType(1);
+ }
+
+ /*
+ * Converts a value generated by the adapted random number generator
+ * into a value in the input domain for the dependent random number
+ * distribution.
+ *
+ * Because the type traits are compile time constants only the
+ * appropriate clause of the if statements will actually be emitted
+ * by the compiler.
+ */
+ _DInputType
+ operator()()
+ {
+ if (is_integral<_DInputType>::value)
+ return _M_g();
+ else
+ return generate_canonical<_DInputType,
+ numeric_limits<_DInputType>::digits,
+ _Engine>(_M_g);
+ }
+
+ private:
+ _Engine& _M_g;
+ };
+ } // namespace __detail
+
+ /**
+ * @addtogroup std_random_generators Random Number Generators
+ * @ingroup std_random
+ *
+ * These classes define objects which provide random or pseudorandom
+ * numbers, either from a discrete or a continuous interval. The
+ * random number generator supplied as a part of this library are
+ * all uniform random number generators which provide a sequence of
+ * random number uniformly distributed over their range.
+ *
+ * A number generator is a function object with an operator() that
+ * takes zero arguments and returns a number.
+ *
+ * A compliant random number generator must satisfy the following
+ * requirements. <table border=1 cellpadding=10 cellspacing=0>
+ * <caption align=top>Random Number Generator Requirements</caption>
+ * <tr><td>To be documented.</td></tr> </table>
+ *
+ * @{
+ */
+
+ /**
+ * @brief A model of a linear congruential random number generator.
+ *
+ * A random number generator that produces pseudorandom numbers using the
+ * linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$.
+ *
+ * The template parameter @p _UIntType must be an unsigned integral type
+ * large enough to store values up to (__m-1). If the template parameter
+ * @p __m is 0, the modulus @p __m used is
+ * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
+ * parameters @p __a and @p __c must be less than @p __m.
+ *
+ * The size of the state is @f$ 1 @f$.
+ */
+ template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+ class linear_congruential_engine
+ {
+ __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
+ static_assert(__m == 0 || (__a < __m && __c < __m),
+ "template arguments out of bounds"
+ " in linear_congruential_engine");
+
+ public:
+ /** The type of the generated random value. */
+ typedef _UIntType result_type;
+
+ /** The multiplier. */
+ static const result_type multiplier = __a;
+ /** An increment. */
+ static const result_type increment = __c;
+ /** The modulus. */
+ static const result_type modulus = __m;
+ static const result_type default_seed = 1UL;
+
+ /**
+ * @brief Constructs a %linear_congruential_engine random number
+ * generator engine with seed @p __s. The default seed value
+ * is 1.
+ *
+ * @param __s The initial seed value.
+ */
+ explicit
+ linear_congruential_engine(result_type __s = default_seed)
+ { this->seed(__s); }
+
+ /**
+ * @brief Constructs a %linear_congruential_engine random number
+ * generator engine seeded from the seed sequence @p __q.
+ *
+ * @param __q the seed sequence.
+ */
+ explicit
+ linear_congruential_engine(seed_seq& __q)
+ { this->seed(__q); }
+
+ /**
+ * @brief Reseeds the %linear_congruential_engine random number generator
+ * engine sequence to the seed @g __s.
+ *
+ * @param __s The new seed.
+ */
+ void
+ seed(result_type __s = default_seed);
+
+ /**
+ * @brief Reseeds the %linear_congruential_engine random number generator
+ * engine
+ * sequence using values from the seed sequence @p __q.
+ *
+ * @param __q the seed sequence.
+ */
+ void
+ seed(seed_seq& __q);
+
+ /**
+ * @brief Gets the smallest possible value in the output range.
+ *
+ * The minimum depends on the @p __c parameter: if it is zero, the
+ * minimum generated must be > 0, otherwise 0 is allowed.
+ *
+ * @todo This should be constexpr.
+ */
+ result_type
+ min() const
+ { return (__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) ? 1 : 0; }
+
+ /**
+ * @brief Gets the largest possible value in the output range.
+ *
+ * @todo This should be constexpr.
+ */
+ result_type
+ max() const
+ { return __m - 1; }
+
+ /**
+ * @brief Discard a sequence of random numbers.
+ *
+ * @todo Look for a faster way to do discard.
+ */
+ void
+ discard(unsigned long long __z)
+ {
+ for (; __z != 0ULL; --__z)
+ (*this)();
+ }
+
+ /**
+ * @brief Gets the next random number in the sequence.
+ */
+ result_type
+ operator()();
+
+ /**
+ * @brief Compares two linear congruential random number generator
+ * objects of the same type for equality.
+ *
+ * @param __lhs A linear congruential random number generator object.
+ * @param __rhs Another linear congruential random number generator
+ * object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const linear_congruential_engine& __lhs,
+ const linear_congruential_engine& __rhs)
+ { return __lhs._M_x == __rhs._M_x; }
+
+ /**
+ * @brief Writes the textual representation of the state x(i) of x to
+ * @p __os.
+ *
+ * @param __os The output stream.
+ * @param __lcr A % linear_congruential_engine random number generator.
+ * @returns __os.
+ */
+ template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
+ _UIntType1 __m1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const linear_congruential_engine<_UIntType1, __a1, __c1,
+ __m1>& __lcr);
+
+ /**
+ * @brief Sets the state of the engine by reading its textual
+ * representation from @p __is.
+ *
+ * The textual representation must have been previously written using
+ * an output stream whose imbued locale and whose type's template
+ * specialization arguments _CharT and _Traits were the same as those
+ * of @p __is.
+ *
+ * @param __is The input stream.
+ * @param __lcr A % linear_congruential_engine random number generator.
+ * @returns __is.
+ */
+ template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
+ _UIntType1 __m1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ linear_congruential_engine<_UIntType1,
+ __a1, __c1, __m1>& __lcr);
+
+ private:
+ template<typename _Gen>
+ void
+ seed(_Gen& __g, true_type)
+ { return seed(static_cast<unsigned long>(__g)); }
+
+ template<typename _Gen>
+ void
+ seed(_Gen& __g, false_type);
+
+ _UIntType _M_x;
+ };
+
+
+ /**
+ * A generalized feedback shift register discrete random number generator.
+ *
+ * This algorithm avoids multiplication and division and is designed to be
+ * friendly to a pipelined architecture. If the parameters are chosen
+ * correctly, this generator will produce numbers with a very long period and
+ * fairly good apparent entropy, although still not cryptographically strong.
+ *
+ * The best way to use this generator is with the predefined mt19937 class.
+ *
+ * This algorithm was originally invented by Makoto Matsumoto and
+ * Takuji Nishimura.
+ *
+ * @var word_size The number of bits in each element of the state vector.
+ * @var state_size The degree of recursion.
+ * @var shift_size The period parameter.
+ * @var mask_bits The separation point bit index.
+ * @var parameter_a The last row of the twist matrix.
+ * @var output_u The first right-shift tempering matrix parameter.
+ * @var output_s The first left-shift tempering matrix parameter.
+ * @var output_b The first left-shift tempering matrix mask.
+ * @var output_t The second left-shift tempering matrix parameter.
+ * @var output_c The second left-shift tempering matrix mask.
+ * @var output_l The second right-shift tempering matrix parameter.
+ */
+ template<typename _UIntType, size_t __w,
+ size_t __n, size_t __m, size_t __r,
+ _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+ _UIntType __b, size_t __t,
+ _UIntType __c, size_t __l, _UIntType __f>
+ class mersenne_twister_engine
+ {
+ __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
+
+ static_assert(__m >= 1U,
+ "mersenne_twister_engine template arguments out of bounds");
+ static_assert(__n >= __m,
+ "mersenne_twister_engine template arguments out of bounds");
+ static_assert(__w >= __r,
+ "mersenne_twister_engine template arguments out of bounds");
+ static_assert(__w >= __u,
+ "mersenne_twister_engine template arguments out of bounds");
+ static_assert(__w >= __s,
+ "mersenne_twister_engine template arguments out of bounds");
+ static_assert(__w >= __t,
+ "mersenne_twister_engine template arguments out of bounds");
+ static_assert(__w >= __l,
+ "mersenne_twister_engine template arguments out of bounds");
+ static_assert(__w <= static_cast<size_t>(numeric_limits<_UIntType>::digits),
+ "mersenne_twister_engine template arguments out of bounds");
+
+#if 0
+ // XXX
+ static_assert(__a <= __detail::_ShiftMin1<_UIntType, __w>::__value,
+ "mersenne_twister_engine template arguments out of bounds");
+ static_assert(__b <= __detail::_ShiftMin1<_UIntType, __w>::__value,
+ "mersenne_twister_engine template arguments out of bounds");
+ static_assert(__c <= __detail::_ShiftMin1<_UIntType, __w>::__value,
+ "mersenne_twister_engine template arguments out of bounds");
+#endif
+
+ public:
+ /** The type of the generated random value. */
+ typedef _UIntType result_type;
+
+ // parameter values
+ static const size_t word_size = __w;
+ static const size_t state_size = __n;
+ static const size_t shift_size = __m;
+ static const size_t mask_bits = __r;
+ static const result_type xor_mask = __a;
+ static const size_t tempering_u = __u;
+ static const result_type tempering_d = __d;
+ static const size_t tempering_s = __s;
+ static const result_type tempering_b = __b;
+ static const size_t tempering_t = __t;
+ static const result_type tempering_c = __c;
+ static const size_t tempering_l = __l;
+ static const size_t initialization_multiplier = __f;
+ static const result_type default_seed = 5489UL;
+
+ // constructors and member function
+ explicit
+ mersenne_twister_engine(result_type __sd = default_seed)
+ { seed(__sd); }
+
+ /**
+ * @brief Constructs a %mersenne_twister_engine random number generator
+ * engine seeded from the seed sequence @p __q.
+ *
+ * @param __q the seed sequence.
+ */
+ explicit
+ mersenne_twister_engine(seed_seq& __q)
+ { seed(__q); }
+
+ void
+ seed(result_type __sd = default_seed);
+
+ void
+ seed(seed_seq& __q);
+
+ /**
+ * @brief Gets the smallest possible value in the output range.
+ *
+ * @todo This should be constexpr.
+ */
+ result_type
+ min() const
+ { return 0; };
+
+ /**
+ * @brief Gets the largest possible value in the output range.
+ *
+ * @todo This should be constexpr.
+ */
+ result_type
+ max() const
+ { return __detail::_ShiftMin1<_UIntType, __w>::__value; }
+
+ /**
+ * @brief Discard a sequence of random numbers.
+ *
+ * @todo Look for a faster way to do discard.
+ */
+ void
+ discard(unsigned long long __z)
+ {
+ for (; __z != 0ULL; --__z)
+ (*this)();
+ }
+
+ result_type
+ operator()();
+
+ /**
+ * @brief Compares two % mersenne_twister_engine random number generator
+ * objects of the same type for equality.
+ *
+ * @param __lhs A % mersenne_twister_engine random number generator
+ * object.
+ * @param __rhs Another % mersenne_twister_engine random number
+ * generator object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const mersenne_twister_engine& __lhs,
+ const mersenne_twister_engine& __rhs)
+ { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
+
+ /**
+ * @brief Inserts the current state of a % mersenne_twister_engine
+ * random number generator engine @p __x into the output stream
+ * @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A % mersenne_twister_engine random number generator
+ * engine.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _UIntType1,
+ size_t __w1, size_t __n1,
+ size_t __m1, size_t __r1,
+ _UIntType1 __a1, size_t __u1,
+ _UIntType1 __d1, size_t __s1,
+ _UIntType1 __b1, size_t __t1,
+ _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const mersenne_twister_engine<_UIntType1, __w1, __n1, __m1, __r1,
+ __a1, __u1, __d1, __s1, __b1, __t1, __c1, __l1, __f1>& __x);
+
+ /**
+ * @brief Extracts the current state of a % mersenne_twister_engine
+ * random number generator engine @p __x from the input stream
+ * @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A % mersenne_twister_engine random number generator
+ * engine.
+ *
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
+ */
+ template<typename _UIntType1,
+ size_t __w1, size_t __n1,
+ size_t __m1, size_t __r1,
+ _UIntType1 __a1, size_t __u1,
+ _UIntType1 __d1, size_t __s1,
+ _UIntType1 __b1, size_t __t1,
+ _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ mersenne_twister_engine<_UIntType1, __w1, __n1, __m1, __r1,
+ __a1, __u1, __d1, __s1, __b1, __t1, __c1, __l1, __f1>& __x);
+
+ private:
+ template<typename _Gen>
+ void
+ seed(_Gen& __g, true_type)
+ { return seed(static_cast<unsigned long>(__g)); }
+
+ template<typename _Gen>
+ void
+ seed(_Gen& __g, false_type);
+
+ _UIntType _M_x[state_size];
+ size_t _M_p;
+ };
+
+ /**
+ * @brief The Marsaglia-Zaman generator.
+ *
+ * This is a model of a Generalized Fibonacci discrete random number
+ * generator, sometimes referred to as the SWC generator.
+ *
+ * A discrete random number generator that produces pseudorandom
+ * numbers using @f$x_{i}\leftarrow(x_{i - s} - x_{i - r} -
+ * carry_{i-1}) \bmod m @f$.
+ *
+ * The size of the state is @f$ r @f$
+ * and the maximum period of the generator is @f$ m^r - m^s - 1 @f$.
+ *
+ * @var _M_x The state of the generator. This is a ring buffer.
+ * @var _M_carry The carry.
+ * @var _M_p Current index of x(i - r).
+ */
+ template<typename _UIntType, size_t __w, size_t __s, size_t __r>
+ class subtract_with_carry_engine
+ {
+ __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
+ static_assert(__s > 0U && __r > __s
+ && __w > 0U
+ && __w <= static_cast<size_t>(numeric_limits<_UIntType>::digits),
+ "template arguments out of bounds"
+ " in subtract_with_carry_engine");
+
+ public:
+ /** The type of the generated random value. */
+ typedef _UIntType result_type;
+
+ // parameter values
+ static const size_t word_size = __w;
+ static const size_t short_lag = __s;
+ static const size_t long_lag = __r;
+ static const result_type default_seed = 19780503;
+
+ /**
+ * @brief Constructs an explicitly seeded % subtract_with_carry_engine
+ * random number generator.
+ */
+ explicit
+ subtract_with_carry_engine(result_type __sd = default_seed)
+ { this->seed(__sd); }
+
+ /**
+ * @brief Constructs a %subtract_with_carry_engine random number engine
+ * seeded from the seed sequence @p __q.
+ *
+ * @param __q the seed sequence.
+ */
+ explicit
+ subtract_with_carry_engine(seed_seq& __q)
+ { this->seed(__q); }
+
+ /**
+ * @brief Seeds the initial state @f$ x_0 @f$ of the random number
+ * generator.
+ *
+ * N1688[4.19] modifies this as follows. If @p __value == 0,
+ * sets value to 19780503. In any case, with a linear
+ * congruential generator lcg(i) having parameters @f$ m_{lcg} =
+ * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
+ * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
+ * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
+ * set carry to 1, otherwise sets carry to 0.
+ */
+ void
+ seed(result_type __sd = default_seed);
+
+ /**
+ * @brief Seeds the initial state @f$ x_0 @f$ of the
+ * % subtract_with_carry_engine random number generator.
+ */
+ void
+ seed(seed_seq& __q);
+
+ /**
+ * @brief Gets the inclusive minimum value of the range of random
+ * integers returned by this generator.
+ *
+ * @todo This should be constexpr.
+ */
+ result_type
+ min() const
+ { return 0; }
+
+ /**
+ * @brief Gets the inclusive maximum value of the range of random
+ * integers returned by this generator.
+ *
+ * @todo This should be constexpr.
+ */
+ result_type
+ max() const
+ { return _S_modulus - 1U; }
+
+ /**
+ * @brief Discard a sequence of random numbers.
+ *
+ * @todo Look for a faster way to do discard.
+ */
+ void
+ discard(unsigned long long __z)
+ {
+ for (; __z != 0ULL; --__z)
+ (*this)();
+ }
+
+ /**
+ * @brief Gets the next random number in the sequence.
+ */
+ result_type
+ operator()();
+
+ /**
+ * @brief Compares two % subtract_with_carry_engine random number
+ * generator objects of the same type for equality.
+ *
+ * @param __lhs A % subtract_with_carry_engine random number generator
+ * object.
+ * @param __rhs Another % subtract_with_carry_engine random number
+ * generator object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const subtract_with_carry_engine& __lhs,
+ const subtract_with_carry_engine& __rhs)
+ { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
+
+ /**
+ * @brief Inserts the current state of a % subtract_with_carry_engine
+ * random number generator engine @p __x into the output stream
+ * @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A % subtract_with_carry_engine random number generator
+ * engine.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const subtract_with_carry_engine<_UIntType1, __w1, __s1,
+ __r1>& __x);
+
+ /**
+ * @brief Extracts the current state of a % subtract_with_carry_engine
+ * random number generator engine @p __x from the input stream
+ * @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A % subtract_with_carry_engine random number generator engine.
+ *
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
+ */
+ template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ subtract_with_carry_engine<_UIntType1, __w1, __s1, __r1>& __x);
+
+ private:
+ template<typename _Gen>
+ void
+ seed(_Gen& __g, true_type)
+ { return seed(static_cast<unsigned long>(__g)); }
+
+ template<typename _Gen>
+ void
+ seed(_Gen& __g, false_type);
+
+ static const size_t _S_modulus
+ = __detail::_Shift<_UIntType, __w>::__value;
+
+ _UIntType _M_x[long_lag];
+ _UIntType _M_carry;
+ size_t _M_p;
+ };
+
+ /**
+ * Produces random numbers from some base engine by discarding blocks of
+ * data.
+ *
+ * 0 <= @p __r <= @p __p
+ */
+ template<typename _RandomNumberEngine, size_t __p, size_t __r>
+ class discard_block_engine
+ {
+ static_assert(__r >= 1U && __p >= __r,
+ "template arguments out of bounds"
+ " in discard_block_engine");
+
+ public:
+ /** The type of the generated random value. */
+ typedef typename _RandomNumberEngine::result_type result_type;
+
+ // parameter values
+ static const size_t block_size = __p;
+ static const size_t used_block = __r;
+
+ /**
+ * @brief Constructs a default %discard_block_engine engine.
+ *
+ * The underlying engine is default constructed as well.
+ */
+ discard_block_engine()
+ : _M_b(), _M_n(0) { }
+
+ /**
+ * @brief Copy constructs a %discard_block_engine engine.
+ *
+ * Copies an existing base class random number generator.
+ * @param rng An existing (base class) engine object.
+ */
+ explicit
+ discard_block_engine(const _RandomNumberEngine& __rne)
+ : _M_b(__rne), _M_n(0) { }
+
+ /**
+ * @brief Move constructs a %discard_block_engine engine.
+ *
+ * Copies an existing base class random number generator.
+ * @param rng An existing (base class) engine object.
+ */
+ explicit
+ discard_block_engine(_RandomNumberEngine&& __rne)
+ : _M_b(std::move(__rne)), _M_n(0) { }
+
+ /**
+ * @brief Seed constructs a %discard_block_engine engine.
+ *
+ * Constructs the underlying generator engine seeded with @p __s.
+ * @param __s A seed value for the base class engine.
+ */
+ explicit
+ discard_block_engine(result_type __s)
+ : _M_b(__s), _M_n(0) { }
+
+ /**
+ * @brief Generator construct a %discard_block_engine engine.
+ *
+ * @param __q A seed sequence.
+ */
+ explicit
+ discard_block_engine(seed_seq& __q)
+ : _M_b(__q), _M_n(0)
+ { }
+
+ /**
+ * @brief Reseeds the %discard_block_engine object with the default
+ * seed for the underlying base class generator engine.
+ */
+ void
+ seed()
+ {
+ _M_b.seed();
+ _M_n = 0;
+ }
+
+ /**
+ * @brief Reseeds the %discard_block_engine object with the default
+ * seed for the underlying base class generator engine.
+ */
+ void
+ seed(result_type __s)
+ {
+ _M_b.seed(__s);
+ _M_n = 0;
+ }
+
+ /**
+ * @brief Reseeds the %discard_block_engine object with the given seed
+ * sequence.
+ * @param __q A seed generator function.
+ */
+ void
+ seed(seed_seq& __q)
+ {
+ _M_b.seed(__q);
+ _M_n = 0;
+ }
+
+ /**
+ * @brief Gets a const reference to the underlying generator engine
+ * object.
+ */
+ const _RandomNumberEngine&
+ base() const
+ { return _M_b; }
+
+ /**
+ * @brief Gets the minimum value in the generated random number range.
+ *
+ * @todo This should be constexpr.
+ */
+ result_type
+ min() const
+ { return _M_b.min(); }
+
+ /**
+ * @brief Gets the maximum value in the generated random number range.
+ *
+ * @todo This should be constexpr.
+ */
+ result_type
+ max() const
+ { return _M_b.max(); }
+
+ /**
+ * @brief Discard a sequence of random numbers.
+ *
+ * @todo Look for a faster way to do discard.
+ */
+ void
+ discard(unsigned long long __z)
+ {
+ for (; __z != 0ULL; --__z)
+ (*this)();
+ }
+
+ /**
+ * @brief Gets the next value in the generated random number sequence.
+ */
+ result_type
+ operator()();
+
+ /**
+ * @brief Compares two %discard_block_engine random number generator
+ * objects of the same type for equality.
+ *
+ * @param __lhs A %discard_block_engine random number generator object.
+ * @param __rhs Another %discard_block_engine random number generator
+ * object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const discard_block_engine& __lhs,
+ const discard_block_engine& __rhs)
+ { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); }
+
+ /**
+ * @brief Inserts the current state of a %discard_block_engine random
+ * number generator engine @p __x into the output stream
+ * @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %discard_block_engine random number generator engine.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const discard_block_engine<_RandomNumberEngine1,
+ __p1, __r1>& __x);
+
+ /**
+ * @brief Extracts the current state of a % subtract_with_carry_engine
+ * random number generator engine @p __x from the input stream
+ * @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %discard_block_engine random number generator engine.
+ *
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
+ */
+ template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ discard_block_engine<_RandomNumberEngine1,
+ __p1, __r1>& __x);
+
+ private:
+ _RandomNumberEngine _M_b;
+ size_t _M_n;
+ };
+
+ /**
+ * Produces random numbers by combining random numbers from some base
+ * engine to produce random numbers with a specifies number of bits @p __w.
+ */
+ template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
+ class independent_bits_engine
+ {
+ static_assert(__w > 0U
+ && __w <= static_cast<size_t>(numeric_limits<_UIntType>::digits),
+ "template arguments out of bounds"
+ " in independent_bits_engine");
+
+ public:
+ /** The type of the generated random value. */
+ typedef _UIntType result_type;
+
+ /**
+ * @brief Constructs a default %independent_bits_engine engine.
+ *
+ * The underlying engine is default constructed as well.
+ */
+ independent_bits_engine()
+ : _M_b() { }
+
+ /**
+ * @brief Copy constructs a %independent_bits_engine engine.
+ *
+ * Copies an existing base class random number generator.
+ * @param rng An existing (base class) engine object.
+ */
+ explicit
+ independent_bits_engine(const _RandomNumberEngine& __rne)
+ : _M_b(__rne) { }
+
+ /**
+ * @brief Move constructs a %independent_bits_engine engine.
+ *
+ * Copies an existing base class random number generator.
+ * @param rng An existing (base class) engine object.
+ */
+ explicit
+ independent_bits_engine(_RandomNumberEngine&& __rne)
+ : _M_b(std::move(__rne)) { }
+
+ /**
+ * @brief Seed constructs a %independent_bits_engine engine.
+ *
+ * Constructs the underlying generator engine seeded with @p __s.
+ * @param __s A seed value for the base class engine.
+ */
+ explicit
+ independent_bits_engine(result_type __s)
+ : _M_b(__s) { }
+
+ /**
+ * @brief Generator construct a %independent_bits_engine engine.
+ *
+ * @param __q A seed sequence.
+ */
+ explicit
+ independent_bits_engine(seed_seq& __q)
+ : _M_b(__q)
+ { }
+
+ /**
+ * @brief Reseeds the %independent_bits_engine object with the default
+ * seed for the underlying base class generator engine.
+ */
+ void
+ seed()
+ { _M_b.seed(); }
+
+ /**
+ * @brief Reseeds the %independent_bits_engine object with the default
+ * seed for the underlying base class generator engine.
+ */
+ void
+ seed(result_type __s)
+ { _M_b.seed(__s); }
+
+ /**
+ * @brief Reseeds the %independent_bits_engine object with the given
+ * seed sequence.
+ * @param __q A seed generator function.
+ */
+ void
+ seed(seed_seq& __q)
+ { _M_b.seed(__q); }
+
+ /**
+ * @brief Gets a const reference to the underlying generator engine
+ * object.
+ */
+ const _RandomNumberEngine&
+ base() const
+ { return _M_b; }
+
+ /**
+ * @brief Gets the minimum value in the generated random number range.
+ *
+ * @todo This should be constexpr.
+ */
+ result_type
+ min() const
+ { return 0U; }
+
+ /**
+ * @brief Gets the maximum value in the generated random number range.
+ *
+ * @todo This should be constexpr.
+ */
+ result_type
+ max() const
+ { return __detail::_ShiftMin1<_UIntType, __w>::__value; }
+
+ /**
+ * @brief Discard a sequence of random numbers.
+ *
+ * @todo Look for a faster way to do discard.
+ */
+ void
+ discard(unsigned long long __z)
+ {
+ for (; __z != 0ULL; --__z)
+ (*this)();
+ }
+
+ /**
+ * @brief Gets the next value in the generated random number sequence.
+ */
+ result_type
+ operator()();
+
+ /**
+ * @brief Compares two %independent_bits_engine random number generator
+ * objects of the same type for equality.
+ *
+ * @param __lhs A %independent_bits_engine random number generator
+ * object.
+ * @param __rhs Another %independent_bits_engine random number generator
+ * object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const independent_bits_engine& __lhs,
+ const independent_bits_engine& __rhs)
+ { return __lhs._M_b == __rhs._M_b; }
+
+ /**
+ * @brief Extracts the current state of a % subtract_with_carry_engine
+ * random number generator engine @p __x from the input stream
+ * @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %independent_bits_engine random number generator
+ * engine.
+ *
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
+ */
+ template<typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ independent_bits_engine<_RandomNumberEngine,
+ __w, _UIntType>& __x)
+ {
+ __is >> __x._M_b;
+ return __is;
+ }
+
+ private:
+ _RandomNumberEngine _M_b;
+ };
+
+ /**
+ * @brief Inserts the current state of a %independent_bits_engine random
+ * number generator engine @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %independent_bits_engine random number generator engine.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const independent_bits_engine<_RandomNumberEngine,
+ __w, _UIntType>& __x)
+ {
+ __os << __x.base();
+ return __os;
+ }
+
+ /**
+ * @brief Produces random numbers by combining random numbers from some
+ * base engine to produce random numbers with a specifies number of bits
+ * @p __w.
+ */
+ template<typename _RandomNumberEngine, size_t __k>
+ class shuffle_order_engine
+ {
+ static_assert(__k >= 1U,
+ "template arguments out of bounds"
+ " in shuffle_order_engine");
+
+ public:
+ /** The type of the generated random value. */
+ typedef typename _RandomNumberEngine::result_type result_type;
+
+ static const size_t table_size = __k;
+
+ /**
+ * @brief Constructs a default %shuffle_order_engine engine.
+ *
+ * The underlying engine is default constructed as well.
+ */
+ shuffle_order_engine()
+ : _M_b()
+ { _M_initialize(); }
+
+ /**
+ * @brief Copy constructs a %shuffle_order_engine engine.
+ *
+ * Copies an existing base class random number generator.
+ * @param rng An existing (base class) engine object.
+ */
+ explicit
+ shuffle_order_engine(const _RandomNumberEngine& __rne)
+ : _M_b(__rne)
+ { _M_initialize(); }
+
+ /**
+ * @brief Move constructs a %shuffle_order_engine engine.
+ *
+ * Copies an existing base class random number generator.
+ * @param rng An existing (base class) engine object.
+ */
+ explicit
+ shuffle_order_engine(_RandomNumberEngine&& __rne)
+ : _M_b(std::move(__rne))
+ { _M_initialize(); }
+
+ /**
+ * @brief Seed constructs a %shuffle_order_engine engine.
+ *
+ * Constructs the underlying generator engine seeded with @p __s.
+ * @param __s A seed value for the base class engine.
+ */
+ explicit
+ shuffle_order_engine(result_type __s)
+ : _M_b(__s)
+ { _M_initialize(); }
+
+ /**
+ * @brief Generator construct a %shuffle_order_engine engine.
+ *
+ * @param __q A seed sequence.
+ */
+ explicit
+ shuffle_order_engine(seed_seq& __q)
+ : _M_b(__q)
+ { _M_initialize(); }
+
+ /**
+ * @brief Reseeds the %shuffle_order_engine object with the default seed for
+ * the underlying base class generator engine.
+ */
+ void
+ seed()
+ {
+ _M_b.seed();
+ _M_initialize();
+ }
+
+ /**
+ * @brief Reseeds the %shuffle_order_engine object with the default seed
+ * for the underlying base class generator engine.
+ */
+ void
+ seed(result_type __s)
+ {
+ _M_b.seed(__s);
+ _M_initialize();
+ }
+
+ /**
+ * @brief Reseeds the %shuffle_order_engine object with the given seed
+ * sequence.
+ * @param __q A seed generator function.
+ */
+ void
+ seed(seed_seq& __q)
+ {
+ _M_b.seed(__q);
+ _M_initialize();
+ }
+
+ /**
+ * Gets a const reference to the underlying generator engine object.
+ */
+ const _RandomNumberEngine&
+ base() const
+ { return _M_b; }
+
+ /**
+ * Gets the minimum value in the generated random number range.
+ *
+ * @todo This should be constexpr.
+ */
+ result_type
+ min() const
+ { return _M_b.min(); }
+
+ /**
+ * Gets the maximum value in the generated random number range.
+ *
+ * @todo This should be constexpr.
+ */
+ result_type
+ max() const
+ { return _M_b.max(); }
+
+ /**
+ * Discard a sequence of random numbers.
+ *
+ * @todo Look for a faster way to do discard.
+ */
+ void
+ discard(unsigned long long __z)
+ {
+ for (; __z != 0ULL; --__z)
+ (*this)();
+ }
+
+ /**
+ * Gets the next value in the generated random number sequence.
+ */
+ result_type
+ operator()();
+
+ /**
+ * Compares two %shuffle_order_engine random number generator objects
+ * of the same type for equality.
+ *
+ * @param __lhs A %shuffle_order_engine random number generator object.
+ * @param __rhs Another %shuffle_order_engine random number generator
+ * object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const shuffle_order_engine& __lhs,
+ const shuffle_order_engine& __rhs)
+ { return __lhs._M_b == __rhs._M_b; }
+
+ /**
+ * @brief Inserts the current state of a %shuffle_order_engine random
+ * number generator engine @p __x into the output stream
+ @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %shuffle_order_engine random number generator engine.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RandomNumberEngine1, size_t __k1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const shuffle_order_engine<_RandomNumberEngine1,
+ __k1>& __x);
+
+ /**
+ * @brief Extracts the current state of a % subtract_with_carry_engine
+ * random number generator engine @p __x from the input stream
+ * @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %shuffle_order_engine random number generator engine.
+ *
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
+ */
+ template<typename _RandomNumberEngine1, size_t __k1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ shuffle_order_engine<_RandomNumberEngine1,
+ __k1>& __x);
+
+ private:
+ void _M_initialize()
+ {
+ for (size_t __i = 0; __i < __k; ++__i)
+ _M_v[__i] = _M_b();
+ _M_y = _M_b();
+ }
+
+ _RandomNumberEngine _M_b;
+ result_type _M_v[__k];
+ result_type _M_y;
+ };
+
+ /**
+ * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
+ */
+ typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
+ minstd_rand0;
+
+ /**
+ * An alternative LCR (Lehmer Generator function) .
+ */
+ typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
+ minstd_rand;
+
+ /**
+ * The classic Mersenne Twister.
+ *
+ * Reference:
+ * M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
+ * Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions
+ * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
+ */
+ typedef mersenne_twister_engine<
+ uint_fast32_t,
+ 32, 624, 397, 31,
+ 0x9908b0dfUL, 11,
+ 0xffffffffUL, 7,
+ 0x9d2c5680UL, 15,
+ 0xefc60000UL, 18, 1812433253UL> mt19937;
+
+ /**
+ * An alternative Mersenne Twister.
+ */
+ typedef mersenne_twister_engine<
+ uint_fast64_t,
+ 64, 312, 156, 31,
+ 0xb5026f5aa96619e9ULL, 29,
+ 0x5555555555555555ULL, 17,
+ 0x71d67fffeda60000ULL, 37,
+ 0xfff7eee000000000ULL, 43,
+ 6364136223846793005ULL> mt19937_64;
+
+ /**
+ * .
+ */
+ typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
+ ranlux24_base;
+
+ typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
+
+ typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
+ ranlux48_base;
+
+ typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
+
+ /**
+ * .
+ */
+ typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
+
+ /**
+ * .
+ */
+ typedef minstd_rand0 default_random_engine;
+
+ /**
+ * A standard interface to a platform-specific non-deterministic
+ * random number generator (if any are available).
+ */
+ class random_device
+ {
+ public:
+ /** The type of the generated random value. */
+ typedef unsigned int result_type;
+
+ // constructors, destructors and member functions
+
+#ifdef _GLIBCXX_USE_RANDOM_TR1
+
+ explicit
+ random_device(const std::string& __token = "/dev/urandom")
+ {
+ if ((__token != "/dev/urandom" && __token != "/dev/random")
+ || !(_M_file = std::fopen(__token.c_str(), "rb")))
+ std::__throw_runtime_error(__N("random_device::"
+ "random_device(const std::string&)"));
+ }
+
+ ~random_device()
+ { std::fclose(_M_file); }
+
+#else
+
+ explicit
+ random_device(const std::string& __token = "mt19937")
+ : _M_mt(_M_strtoul(__token)) { }
+
+ private:
+ static unsigned long
+ _M_strtoul(const std::string& __str)
+ {
+ unsigned long __ret = 5489UL;
+ if (__str != "mt19937")
+ {
+ const char* __nptr = __str.c_str();
+ char* __endptr;
+ __ret = std::strtoul(__nptr, &__endptr, 0);
+ if (*__nptr == '\0' || *__endptr != '\0')
+ std::__throw_runtime_error(__N("random_device::_M_strtoul"
+ "(const std::string&)"));
+ }
+ return __ret;
+ }
+
+ public:
+
+#endif
+
+ result_type
+ min() const
+ { return std::numeric_limits<result_type>::min(); }
+
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ double
+ entropy() const
+ { return 0.0; }
+
+ result_type
+ operator()()
+ {
+#ifdef _GLIBCXX_USE_RANDOM_TR1
+ result_type __ret;
+ std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
+ 1, _M_file);
+ return __ret;
+#else
+ return _M_mt();
+#endif
+ }
+
+ // No copy functions.
+ random_device(const random_device&) = delete;
+ void operator=(const random_device&) = delete;
+
+ private:
+
+#ifdef _GLIBCXX_USE_RANDOM_TR1
+ FILE* _M_file;
+#else
+ mt19937 _M_mt;
+#endif
+ };
+
+ /* @} */ // group std_random_generators
+
+ /**
+ * @addtogroup std_random_distributions Random Number Distributions
+ * @ingroup std_random
+ * @{
+ */
+
+ /**
+ * @addtogroup std_random_distributions_uniform Uniform Distributions
+ * @ingroup std_random_distributions
+ * @{
+ */
+
+ /**
+ * @brief Uniform discrete distribution for random numbers.
+ * A discrete random distribution on the range @f$[min, max]@f$ with equal
+ * probability throughout the range.
+ */
+ template<typename _IntType = int>
+ class uniform_int_distribution
+ {
+ __glibcxx_class_requires(_IntType, _IntegerConcept)
+
+ public:
+ /** The type of the range of the distribution. */
+ typedef _IntType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef uniform_int_distribution<_IntType> distribution_type;
+
+ explicit
+ param_type(_IntType __a = 0, _IntType __b = 9)
+ : _M_a(__a), _M_b(__b)
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
+ }
+
+ result_type
+ a() const
+ { return _M_a; }
+
+ result_type
+ b() const
+ { return _M_b; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_a == __p2._M_a) && (__p1._M_b == __p2._M_b); }
+
+ private:
+ _IntType _M_a;
+ _IntType _M_b;
+ };
+
+ public:
+ /**
+ * @brief Constructs a uniform distribution object.
+ */
+ explicit
+ uniform_int_distribution(_IntType __a = 0, _IntType __b = 9)
+ : _M_param(__a, __b)
+ { }
+
+ explicit
+ uniform_int_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ *
+ * Does nothing for the uniform integer distribution.
+ */
+ void
+ reset() { }
+
+ result_type
+ a() const
+ { return _M_param.a(); }
+
+ result_type
+ b() const
+ { return _M_param.b(); }
+
+ /**
+ * @brief Returns the inclusive lower bound of the distribution range.
+ */
+ result_type
+ min() const
+ { return this->a(); }
+
+ /**
+ * @brief Returns the inclusive upper bound of the distribution range.
+ */
+ result_type
+ max() const
+ { return this->b(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * Gets a uniformly distributed random number in the range
+ * @f$(min, max)@f$.
+ */
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ {
+ typedef typename _UniformRandomNumberGenerator::result_type
+ _UResult_type;
+ return _M_call(__urng, this->a(), this->b(),
+ typename is_integral<_UResult_type>::type());
+ }
+
+ /**
+ * Gets a uniform random number in the range @f$[0, n)@f$.
+ *
+ * This function is aimed at use with std::random_shuffle.
+ */
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ typedef typename _UniformRandomNumberGenerator::result_type
+ _UResult_type;
+ return _M_call(__urng, __p.a(), __p.b(),
+ typename is_integral<_UResult_type>::type());
+ }
+
+ private:
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ _M_call(_UniformRandomNumberGenerator& __urng,
+ result_type __min, result_type __max, true_type);
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ _M_call(_UniformRandomNumberGenerator& __urng,
+ result_type __min, result_type __max, false_type)
+ {
+ return result_type((__urng() - __urng.min())
+ / (__urng.max() - __urng.min())
+ * (__max - __min + 1)) + __min;
+ }
+
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two uniform integer distributions have
+ * the same parameters.
+ */
+ template<typename _IntType>
+ bool
+ operator==(const uniform_int_distribution<_IntType>& __d1,
+ const uniform_int_distribution<_IntType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %uniform_int_distribution random number
+ * distribution @p __x into the output stream @p os.
+ *
+ * @param __os An output stream.
+ * @param __x A %uniform_int_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _IntType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const uniform_int_distribution<_IntType>& __x);
+
+ /**
+ * @brief Extracts a %uniform_int_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %uniform_int_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _IntType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ uniform_int_distribution<_IntType>& __x);
+
+
+ /**
+ * @brief Uniform continuous distribution for random numbers.
+ *
+ * A continuous random distribution on the range [min, max) with equal
+ * probability throughout the range. The URNG should be real-valued and
+ * deliver number in the range [0, 1).
+ */
+ template<typename _RealType = double>
+ class uniform_real_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef uniform_real_distribution<_RealType> distribution_type;
+
+ explicit
+ param_type(_RealType __a = _RealType(0),
+ _RealType __b = _RealType(1))
+ : _M_a(__a), _M_b(__b)
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
+ }
+
+ result_type
+ a() const
+ { return _M_a; }
+
+ result_type
+ b() const
+ { return _M_b; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_a == __p2._M_a) && (__p1._M_b == __p2._M_b); }
+
+ private:
+ _RealType _M_a;
+ _RealType _M_b;
+ };
+
+ public:
+ /**
+ * @brief Constructs a uniform_real_distribution object.
+ *
+ * @param __min [IN] The lower bound of the distribution.
+ * @param __max [IN] The upper bound of the distribution.
+ */
+ explicit
+ uniform_real_distribution(_RealType __a = _RealType(0),
+ _RealType __b = _RealType(1))
+ : _M_param(__a, __b)
+ { }
+
+ explicit
+ uniform_real_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ *
+ * Does nothing for the uniform real distribution.
+ */
+ void
+ reset() { }
+
+ result_type
+ a() const
+ { return _M_param.a(); }
+
+ result_type
+ b() const
+ { return _M_param.b(); }
+
+ /**
+ * @brief Returns the inclusive lower bound of the distribution range.
+ */
+ result_type
+ min() const
+ { return this->a(); }
+
+ /**
+ * @brief Returns the inclusive upper bound of the distribution range.
+ */
+ result_type
+ max() const
+ { return this->b(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ {
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+ return (__aurng() * (this->b() - this->a())) + this->a();
+ }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+ return (__aurng() * (__p.b() - __p.a())) + __p.a();
+ }
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two uniform real distributions have
+ * the same parameters.
+ */
+ template<typename _IntType>
+ bool
+ operator==(const uniform_real_distribution<_IntType>& __d1,
+ const uniform_real_distribution<_IntType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %uniform_real_distribution random number
+ * distribution @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %uniform_real_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const uniform_real_distribution<_RealType>& __x);
+
+ /**
+ * @brief Extracts a %uniform_real_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %uniform_real_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ uniform_real_distribution<_RealType>& __x);
+
+ /* @} */ // group std_random_distributions_uniform
+
+ /**
+ * @addtogroup std_random_distributions_normal Normal Distributions
+ * @ingroup std_random_distributions
+ * @{
+ */
+
+ /**
+ * @brief A normal continuous distribution for random numbers.
+ *
+ * The formula for the normal probability density function is
+ * @f$ p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
+ * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} } @f$.
+ */
+ template<typename _RealType = double>
+ class normal_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef normal_distribution<_RealType> distribution_type;
+
+ explicit
+ param_type(_RealType __mean = _RealType(0),
+ _RealType __stddev = _RealType(1))
+ : _M_mean(__mean), _M_stddev(__stddev)
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
+ }
+
+ _RealType
+ mean() const
+ { return _M_mean; }
+
+ _RealType
+ stddev() const
+ { return _M_stddev; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_mean == __p2._M_mean)
+ && (__p1._M_stddev == __p2._M_stddev); }
+
+ private:
+ _RealType _M_mean;
+ _RealType _M_stddev;
+ };
+
+ public:
+ /**
+ * Constructs a normal distribution with parameters @f$ mean @f$ and
+ * standard deviation.
+ */
+ explicit
+ normal_distribution(result_type __mean = result_type(0),
+ result_type __stddev = result_type(1))
+ : _M_param(__mean, __stddev), _M_saved_available(false)
+ { }
+
+ explicit
+ normal_distribution(const param_type& __p)
+ : _M_param(__p), _M_saved_available(false)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ */
+ void
+ reset()
+ { _M_saved_available = false; }
+
+ /**
+ * @brief Returns the mean of the distribution.
+ */
+ _RealType
+ mean() const
+ { return _M_param.mean(); }
+
+ /**
+ * @brief Returns the standard deviation of the distribution.
+ */
+ _RealType
+ stddev() const
+ { return _M_param.stddev(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return std::numeric_limits<result_type>::min(); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ /**
+ * @brief Return true if two normal distributions have
+ * the same parameters.
+ */
+ template<typename _RealType1>
+ friend bool
+ operator==(const normal_distribution<_RealType1>& __d1,
+ const normal_distribution<_RealType1>& __d2);
+
+ /**
+ * @brief Inserts a %normal_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %normal_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType1, typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const normal_distribution<_RealType1>& __x);
+
+ /**
+ * @brief Extracts a %normal_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %normal_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error
+ * state.
+ */
+ template<typename _RealType1, typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ normal_distribution<_RealType1>& __x);
+
+ private:
+ param_type _M_param;
+ result_type _M_saved;
+ bool _M_saved_available;
+ };
+
+
+ /**
+ * @brief A lognormal_distribution random number distribution.
+ *
+ * The formula for the normal probability mass function is
+ * @f$ p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
+ * \exp{-\frac{(\ln{x} - m)^2}{2s^2}} @f$
+ */
+ template<typename _RealType = double>
+ class lognormal_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef lognormal_distribution<_RealType> distribution_type;
+
+ explicit
+ param_type(_RealType __m = _RealType(0),
+ _RealType __s = _RealType(1))
+ : _M_m(__m), _M_s(__s)
+ { }
+
+ _RealType
+ m() const
+ { return _M_m; }
+
+ _RealType
+ s() const
+ { return _M_s; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_m == __p2._M_m) && (__p1._M_s == __p2._M_s); }
+
+ private:
+ _RealType _M_m;
+ _RealType _M_s;
+ };
+
+ explicit
+ lognormal_distribution(_RealType __m = _RealType(0),
+ _RealType __s = _RealType(1))
+ : _M_param(__m, __s)
+ { }
+
+ explicit
+ lognormal_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * Resets the distribution state.
+ */
+ void
+ reset()
+ { }
+
+ /**
+ *
+ */
+ _RealType
+ m() const
+ { return _M_param.m(); }
+
+ _RealType
+ s() const
+ { return _M_param.s(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return result_type(0); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two lognormal distributions have
+ * the same parameters.
+ */
+ template<typename _RealType>
+ bool
+ operator==(const lognormal_distribution<_RealType>& __d1,
+ const lognormal_distribution<_RealType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %lognormal_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %lognormal_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const lognormal_distribution<_RealType>& __x);
+
+ /**
+ * @brief Extracts a %lognormal_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %lognormal_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ lognormal_distribution<_RealType>& __x);
+
+
+ /**
+ * @brief A chi_squared_distribution random number distribution.
+ *
+ * The formula for the normal probability mass function is
+ * @f$ p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}} @f$
+ */
+ template<typename _RealType = double>
+ class chi_squared_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef chi_squared_distribution<_RealType> distribution_type;
+
+ explicit
+ param_type(_RealType __n = _RealType(1))
+ : _M_n(__n)
+ { }
+
+ _RealType
+ n() const
+ { return _M_n; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return __p1._M_n == __p2._M_n; }
+
+ private:
+ _RealType _M_n;
+ };
+
+ explicit
+ chi_squared_distribution(_RealType __n = _RealType(1))
+ : _M_param(__n)
+ { }
+
+ explicit
+ chi_squared_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ */
+ void
+ reset()
+ { }
+
+ /**
+ *
+ */
+ _RealType
+ n() const
+ { return _M_param.n(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return result_type(0); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two Chi-squared distributions have
+ * the same parameters.
+ */
+ template<typename _RealType>
+ bool
+ operator==(const chi_squared_distribution<_RealType>& __d1,
+ const chi_squared_distribution<_RealType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %chi_squared_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %chi_squared_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const chi_squared_distribution<_RealType>& __x);
+
+ /**
+ * @brief Extracts a %chi_squared_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %chi_squared_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ chi_squared_distribution<_RealType>& __x);
+
+
+ /**
+ * @brief A cauchy_distribution random number distribution.
+ *
+ * The formula for the normal probability mass function is
+ * @f$ p(x|a,b) = \( \pi b \( 1 + \( \frac{x-a}{b} \)^2 \) \)^{-1} @f$
+ */
+ template<typename _RealType = double>
+ class cauchy_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef cauchy_distribution<_RealType> distribution_type;
+
+ explicit
+ param_type(_RealType __a = _RealType(0),
+ _RealType __b = _RealType(1))
+ : _M_a(__a), _M_b(__b)
+ { }
+
+ _RealType
+ a() const
+ { return _M_a; }
+
+ _RealType
+ b() const
+ { return _M_b; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_a == __p2._M_a) && (__p1._M_b == __p2._M_b); }
+
+ private:
+ _RealType _M_a;
+ _RealType _M_b;
+ };
+
+ explicit
+ cauchy_distribution(_RealType __a = _RealType(0),
+ _RealType __b = _RealType(1))
+ : _M_param(__a, __b)
+ { }
+
+ explicit
+ cauchy_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ */
+ void
+ reset()
+ { }
+
+ /**
+ *
+ */
+ _RealType
+ a() const
+ { return _M_param.a(); }
+
+ _RealType
+ b() const
+ { return _M_param.b(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return std::numeric_limits<result_type>::min(); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two Cauchy distributions have
+ * the same parameters.
+ */
+ template<typename _RealType>
+ bool
+ operator==(const cauchy_distribution<_RealType>& __d1,
+ const cauchy_distribution<_RealType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %cauchy_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %cauchy_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const cauchy_distribution<_RealType>& __x);
+
+ /**
+ * @brief Extracts a %cauchy_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %cauchy_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ cauchy_distribution<_RealType>& __x);
+
+
+ /**
+ * @brief A fisher_f_distribution random number distribution.
+ *
+ * The formula for the normal probability mass function is
+ * @f$ p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
+ * \(\frac{m}{n}\)^{m/2} x^{(m/2)-1}
+ * \( 1 + \frac{mx}{n} \)^{-(m+n)/2} @f$
+ */
+ template<typename _RealType = double>
+ class fisher_f_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef fisher_f_distribution<_RealType> distribution_type;
+
+ explicit
+ param_type(_RealType __m = _RealType(1),
+ _RealType __n = _RealType(1))
+ : _M_m(__m), _M_n(__n)
+ { }
+
+ _RealType
+ m() const
+ { return _M_m; }
+
+ _RealType
+ n() const
+ { return _M_n; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_m == __p2._M_m) && (__p1._M_n == __p2._M_n); }
+
+ private:
+ _RealType _M_m;
+ _RealType _M_n;
+ };
+
+ explicit
+ fisher_f_distribution(_RealType __m = _RealType(1),
+ _RealType __n = _RealType(1))
+ : _M_param(__m, __n)
+ { }
+
+ explicit
+ fisher_f_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ */
+ void
+ reset()
+ { }
+
+ /**
+ *
+ */
+ _RealType
+ m() const
+ { return _M_param.m(); }
+
+ _RealType
+ n() const
+ { return _M_param.n(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return result_type(0); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two Fisher f distributions have
+ * the same parameters.
+ */
+ template<typename _RealType>
+ bool
+ operator==(const fisher_f_distribution<_RealType>& __d1,
+ const fisher_f_distribution<_RealType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %fisher_f_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %fisher_f_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const fisher_f_distribution<_RealType>& __x);
+
+ /**
+ * @brief Extracts a %fisher_f_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %fisher_f_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ fisher_f_distribution<_RealType>& __x);
+
+
+ /**
+ * @brief A student_t_distribution random number distribution.
+ *
+ * The formula for the normal probability mass function is
+ * @f$ p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
+ * \( 1 + \frac{x^2}{n} \) ^{-(n+1)/2} @f$
+ */
+ template<typename _RealType = double>
+ class student_t_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef student_t_distribution<_RealType> distribution_type;
+
+ explicit
+ param_type(_RealType __n = _RealType(1))
+ : _M_n(__n)
+ { }
+
+ _RealType
+ n() const
+ { return _M_n; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return __p1._M_n == __p2._M_n; }
+
+ private:
+ _RealType _M_n;
+ };
+
+ explicit
+ student_t_distribution(_RealType __n = _RealType(1))
+ : _M_param(__n)
+ { }
+
+ explicit
+ student_t_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ */
+ void
+ reset()
+ { }
+
+ /**
+ *
+ */
+ _RealType
+ n() const
+ { return _M_param.n(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return std::numeric_limits<result_type>::min(); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ private:
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ _M_gaussian(_UniformRandomNumberGenerator& __urng,
+ const result_type __sigma);
+
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two Student t distributions have
+ * the same parameters.
+ */
+ template<typename _RealType>
+ bool
+ operator==(const student_t_distribution<_RealType>& __d1,
+ const student_t_distribution<_RealType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %student_t_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %student_t_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const student_t_distribution<_RealType>& __x);
+
+ /**
+ * @brief Extracts a %student_t_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %student_t_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ student_t_distribution<_RealType>& __x);
+
+ /* @} */ // group std_random_distributions_normal
+
+ /**
+ * @addtogroup std_random_distributions_bernoulli Bernoulli Distributions
+ * @ingroup std_random_distributions
+ * @{
+ */
+
+ /**
+ * @brief A Bernoulli random number distribution.
+ *
+ * Generates a sequence of true and false values with likelihood @f$ p @f$
+ * that true will come up and @f$ (1 - p) @f$ that false will appear.
+ */
+ class bernoulli_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef bool result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef bernoulli_distribution distribution_type;
+
+ explicit
+ param_type(double __p = 0.5)
+ : _M_p(__p)
+ {
+ _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
+ }
+
+ double
+ p() const
+ { return _M_p; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return __p1._M_p == __p2._M_p; }
+
+ private:
+ double _M_p;
+ };
+
+ public:
+ /**
+ * @brief Constructs a Bernoulli distribution with likelihood @p p.
+ *
+ * @param __p [IN] The likelihood of a true result being returned.
+ * Must be in the interval @f$ [0, 1] @f$.
+ */
+ explicit
+ bernoulli_distribution(double __p = 0.5)
+ : _M_param(__p)
+ { }
+
+ explicit
+ bernoulli_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ *
+ * Does nothing for a Bernoulli distribution.
+ */
+ void
+ reset() { }
+
+ /**
+ * @brief Returns the @p p parameter of the distribution.
+ */
+ double
+ p() const
+ { return _M_param.p(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return std::numeric_limits<result_type>::min(); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ /**
+ * @brief Returns the next value in the Bernoullian sequence.
+ */
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ {
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
+ __aurng(__urng);
+ if ((__aurng() - __aurng.min())
+ < this->p() * (__aurng.max() - __aurng.min()))
+ return true;
+ return false;
+ }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
+ __aurng(__urng);
+ if ((__aurng() - __aurng.min())
+ < __p.p() * (__aurng.max() - __aurng.min()))
+ return true;
+ return false;
+ }
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two Bernoulli distributions have
+ * the same parameters.
+ */
+ bool
+ operator==(const bernoulli_distribution& __d1,
+ const bernoulli_distribution& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %bernoulli_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %bernoulli_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const bernoulli_distribution& __x);
+
+ /**
+ * @brief Extracts a %bernoulli_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %bernoulli_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ bernoulli_distribution& __x)
+ {
+ double __p;
+ __is >> __p;
+ __x.param(bernoulli_distribution::param_type(__p));
+ return __is;
+ }
+
+
+ /**
+ * @brief A discrete binomial random number distribution.
+ *
+ * The formula for the binomial probability density function is
+ * @f$ p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$
+ * and @f$ p @f$ are the parameters of the distribution.
+ */
+ template<typename _IntType = int>
+ class binomial_distribution
+ {
+ __glibcxx_class_requires(_IntType, _IntegerConcept)
+
+ public:
+ /** The type of the range of the distribution. */
+ typedef _IntType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef binomial_distribution<_IntType> distribution_type;
+ friend class binomial_distribution<_IntType>;
+
+ explicit
+ param_type(_IntType __t = _IntType(1), double __p = 0.5)
+ : _M_t(__t), _M_p(__p)
+ {
+ _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
+ && (_M_p >= 0.0)
+ && (_M_p <= 1.0));
+ _M_initialize();
+ }
+
+ _IntType
+ t() const
+ { return _M_t; }
+
+ double
+ p() const
+ { return _M_p; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_t == __p2._M_t) && (__p1._M_p == __p2._M_p); }
+
+ private:
+ void
+ _M_initialize();
+
+ _IntType _M_t;
+ double _M_p;
+
+ double _M_q;
+#if _GLIBCXX_USE_C99_MATH_TR1
+ double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
+ _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
+#endif
+ bool _M_easy;
+ };
+
+ // constructors and member function
+ explicit
+ binomial_distribution(_IntType __t = _IntType(1),
+ double __p = 0.5)
+ : _M_param(__t, __p), _M_nd()
+ { }
+
+ explicit
+ binomial_distribution(const param_type& __p)
+ : _M_param(__p), _M_nd()
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ */
+ void
+ reset()
+ { _M_nd.reset(); }
+
+ /**
+ * @brief Returns the distribution @p t parameter.
+ */
+ _IntType
+ t() const
+ { return _M_param.t(); }
+
+ /**
+ * @brief Returns the distribution @p p parameter.
+ */
+ double
+ p() const
+ { return _M_param.p(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return 0; }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return _M_param.t(); }
+
+ /**
+ * @brief Return true if two binomial distributions have
+ * the same parameters.
+ */
+ template<typename _IntType1>
+ friend bool
+ operator==(const binomial_distribution<_IntType1>& __d1,
+ const binomial_distribution<_IntType1>& __d2)
+ { return (__d1.param() == __d2.param())
+ && (__d1._M_nd == __d2._M_nd); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ /**
+ * @brief Inserts a %binomial_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %binomial_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _IntType1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const binomial_distribution<_IntType1>& __x);
+
+ /**
+ * @brief Extracts a %binomial_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %binomial_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error
+ * state.
+ */
+ template<typename _IntType1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ binomial_distribution<_IntType1>& __x);
+
+ private:
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
+
+ param_type _M_param;
+
+ // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
+ normal_distribution<double> _M_nd;
+ };
+
+
+ /**
+ * @brief A discrete geometric random number distribution.
+ *
+ * The formula for the geometric probability density function is
+ * @f$ p(i|p) = (1 - p)p^{i-1} @f$ where @f$ p @f$ is the parameter of the
+ * distribution.
+ */
+ template<typename _IntType = int>
+ class geometric_distribution
+ {
+ __glibcxx_class_requires(_IntType, _IntegerConcept)
+
+ public:
+ /** The type of the range of the distribution. */
+ typedef _IntType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef geometric_distribution<_IntType> distribution_type;
+ friend class geometric_distribution<_IntType>;
+
+ explicit
+ param_type(double __p = 0.5)
+ : _M_p(__p)
+ {
+ _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0)
+ && (_M_p <= 1.0));
+ _M_initialize();
+ }
+
+ double
+ p() const
+ { return _M_p; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return __p1._M_p == __p2._M_p; }
+
+ private:
+ void
+ _M_initialize()
+ { _M_log_p = std::log(_M_p); }
+
+ double _M_p;
+
+ double _M_log_p;
+ };
+
+ // constructors and member function
+ explicit
+ geometric_distribution(double __p = 0.5)
+ : _M_param(__p)
+ { }
+
+ explicit
+ geometric_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ *
+ * Does nothing for the geometric distribution.
+ */
+ void
+ reset() { }
+
+ /**
+ * @brief Returns the distribution parameter @p p.
+ */
+ double
+ p() const
+ { return _M_param.p(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return 0; }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two geometric distributions have
+ * the same parameters.
+ */
+ template<typename _IntType>
+ bool
+ operator==(const geometric_distribution<_IntType>& __d1,
+ const geometric_distribution<_IntType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %geometric_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %geometric_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _IntType,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const geometric_distribution<_IntType>& __x);
+
+ /**
+ * @brief Extracts a %geometric_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %geometric_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _IntType,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ geometric_distribution<_IntType>& __x);
+
+
+ /**
+ * @brief A negative_binomial_distribution random number distribution.
+ *
+ * The formula for the negative binomial probability mass function is
+ * @f$ p(i) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$
+ * and @f$ p @f$ are the parameters of the distribution.
+ */
+ template<typename _IntType = int>
+ class negative_binomial_distribution
+ {
+ __glibcxx_class_requires(_IntType, _IntegerConcept)
+
+ public:
+ /** The type of the range of the distribution. */
+ typedef _IntType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef negative_binomial_distribution<_IntType> distribution_type;
+
+ explicit
+ param_type(_IntType __k = 1, double __p = 0.5)
+ : _M_k(__k), _M_p(__p)
+ { }
+
+ _IntType
+ k() const
+ { return _M_k; }
+
+ double
+ p() const
+ { return _M_p; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_k == __p2._M_k) && (__p1._M_p == __p2._M_p); }
+
+ private:
+ _IntType _M_k;
+ double _M_p;
+ };
+
+ explicit
+ negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
+ : _M_param(__k, __p)
+ { }
+
+ explicit
+ negative_binomial_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ */
+ void
+ reset()
+ { }
+
+ /**
+ * @brief Return the @f$ k @f$ parameter of the distribution.
+ */
+ _IntType
+ k() const
+ { return _M_param.k(); }
+
+ /**
+ * @brief Return the @f$ p @f$ parameter of the distribution.
+ */
+ double
+ p() const
+ { return _M_param.p(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return result_type(0); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two negative binomial distributions have
+ * the same parameters.
+ */
+ template<typename _IntType>
+ bool
+ operator==(const negative_binomial_distribution<_IntType>& __d1,
+ const negative_binomial_distribution<_IntType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %negative_binomial_distribution random
+ * number distribution @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %negative_binomial_distribution random number
+ * distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _IntType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const negative_binomial_distribution<_IntType>& __x);
+
+ /**
+ * @brief Extracts a %negative_binomial_distribution random number
+ * distribution @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %negative_binomial_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _IntType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ negative_binomial_distribution<_IntType>& __x);
+
+ /* @} */ // group std_random_distributions_bernoulli
+
+ /**
+ * @addtogroup std_random_distributions_poisson Poisson Distributions
+ * @ingroup std_random_distributions
+ * @{
+ */
+
+ /**
+ * @brief A discrete Poisson random number distribution.
+ *
+ * The formula for the Poisson probability density function is
+ * @f$ p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu} @f$ where @f$ \mu @f$ is the
+ * parameter of the distribution.
+ */
+ template<typename _IntType = int>
+ class poisson_distribution
+ {
+ __glibcxx_class_requires(_IntType, _IntegerConcept)
+
+ public:
+ /** The type of the range of the distribution. */
+ typedef _IntType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef poisson_distribution<_IntType> distribution_type;
+ friend class poisson_distribution<_IntType>;
+
+ explicit
+ param_type(double __mean = 1.0)
+ : _M_mean(__mean)
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
+ _M_initialize();
+ }
+
+ double
+ mean() const
+ { return _M_mean; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return __p1._M_mean == __p2._M_mean; }
+
+ private:
+ // Hosts either log(mean) or the threshold of the simple method.
+ void
+ _M_initialize();
+
+ double _M_mean;
+
+ double _M_lm_thr;
+#if _GLIBCXX_USE_C99_MATH_TR1
+ double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
+#endif
+ };
+
+ // constructors and member function
+ explicit
+ poisson_distribution(double __mean = 1.0)
+ : _M_param(__mean), _M_nd()
+ { }
+
+ explicit
+ poisson_distribution(const param_type& __p)
+ : _M_param(__p), _M_nd()
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ */
+ void
+ reset()
+ { _M_nd.reset(); }
+
+ /**
+ * @brief Returns the distribution parameter @p mean.
+ */
+ double
+ mean() const
+ { return _M_param.mean(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return 0; }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ /**
+ * @brief Return true if two Poisson distributions have the same
+ * parameters.
+ */
+ template<typename _IntType1>
+ friend bool
+ operator==(const poisson_distribution<_IntType1>& __d1,
+ const poisson_distribution<_IntType1>& __d2)
+ { return (__d1.param() == __d2.param())
+ && (__d1._M_nd == __d2._M_nd); }
+
+ /**
+ * @brief Inserts a %poisson_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %poisson_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _IntType1, typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const poisson_distribution<_IntType1>& __x);
+
+ /**
+ * @brief Extracts a %poisson_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %poisson_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error
+ * state.
+ */
+ template<typename _IntType1, typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ poisson_distribution<_IntType1>& __x);
+
+ private:
+ param_type _M_param;
+
+ // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
+ normal_distribution<double> _M_nd;
+ };
+
+ /**
+ * @brief An exponential continuous distribution for random numbers.
+ *
+ * The formula for the exponential probability density function is
+ * @f$ p(x|\lambda) = \lambda e^{-\lambda x} @f$.
+ *
+ * <table border=1 cellpadding=10 cellspacing=0>
+ * <caption align=top>Distribution Statistics</caption>
+ * <tr><td>Mean</td><td>@f$ \frac{1}{\lambda} @f$</td></tr>
+ * <tr><td>Median</td><td>@f$ \frac{\ln 2}{\lambda} @f$</td></tr>
+ * <tr><td>Mode</td><td>@f$ zero @f$</td></tr>
+ * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
+ * <tr><td>Standard Deviation</td><td>@f$ \frac{1}{\lambda} @f$</td></tr>
+ * </table>
+ */
+ template<typename _RealType = double>
+ class exponential_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef exponential_distribution<_RealType> distribution_type;
+
+ explicit
+ param_type(_RealType __lambda = _RealType(1))
+ : _M_lambda(__lambda)
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
+ }
+
+ _RealType
+ lambda() const
+ { return _M_lambda; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return __p1._M_lambda == __p2._M_lambda; }
+
+ private:
+ _RealType _M_lambda;
+ };
+
+ public:
+ /**
+ * @brief Constructs an exponential distribution with inverse scale
+ * parameter @f$ \lambda @f$.
+ */
+ explicit
+ exponential_distribution(const result_type& __lambda = result_type(1))
+ : _M_param(__lambda)
+ { }
+
+ explicit
+ exponential_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ *
+ * Has no effect on exponential distributions.
+ */
+ void
+ reset() { }
+
+ /**
+ * @brief Returns the inverse scale parameter of the distribution.
+ */
+ _RealType
+ lambda() const
+ { return _M_param.lambda(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return result_type(0); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ {
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+ return -std::log(__aurng()) / this->lambda();
+ }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+ return -std::log(__aurng()) / __p.lambda();
+ }
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two exponential distributions have the same
+ * parameters.
+ */
+ template<typename _RealType>
+ bool
+ operator==(const exponential_distribution<_RealType>& __d1,
+ const exponential_distribution<_RealType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %exponential_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %exponential_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const exponential_distribution<_RealType>& __x);
+
+ /**
+ * @brief Extracts a %exponential_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %exponential_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ exponential_distribution<_RealType>& __x);
+
+
+ /**
+ * @brief A gamma continuous distribution for random numbers.
+ *
+ * The formula for the gamma probability density function is
+ * @f$ p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
+ * (x/\beta)^{\alpha - 1} e^{-x/\beta} @f$.
+ */
+ template<typename _RealType = double>
+ class gamma_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef gamma_distribution<_RealType> distribution_type;
+ friend class gamma_distribution<_RealType>;
+
+ explicit
+ param_type(_RealType __alpha = _RealType(1),
+ _RealType __beta = _RealType(1))
+ : _M_alpha(__alpha), _M_beta(__beta)
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
+ _M_initialize();
+ }
+
+ _RealType
+ alpha() const
+ { return _M_alpha; }
+
+ _RealType
+ beta() const
+ { return _M_beta; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_alpha == __p2._M_alpha)
+ && (__p1._M_beta == __p2._M_beta); }
+
+ private:
+ void
+ _M_initialize();
+
+ _RealType _M_alpha;
+ _RealType _M_beta;
+
+ // Hosts either lambda of GB or d of modified Vaduva's.
+ _RealType _M_l_d;
+ };
+
+ public:
+ /**
+ * @brief Constructs a gamma distribution with parameters
+ * @f$ \alpha @f$ and @f$ \beta @f$.
+ */
+ explicit
+ gamma_distribution(_RealType __alpha = _RealType(1),
+ _RealType __beta = _RealType(1))
+ : _M_param(__alpha, __beta)
+ { }
+
+ explicit
+ gamma_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ *
+ * Does nothing for the gamma distribution.
+ */
+ void
+ reset() { }
+
+ /**
+ * @brief Returns the @f$ \alpha @f$ of the distribution.
+ */
+ _RealType
+ alpha() const
+ { return _M_param.alpha(); }
+
+ /**
+ * @brief Returns the @f$ \beta @f$ of the distribution.
+ */
+ _RealType
+ beta() const
+ { return _M_param.beta(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return result_type(0); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two gamma distributions have the same
+ * parameters.
+ */
+ template<typename _RealType>
+ bool
+ operator==(const gamma_distribution<_RealType>& __d1,
+ const gamma_distribution<_RealType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %gamma_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %gamma_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const gamma_distribution<_RealType>& __x);
+
+ /**
+ * @brief Extracts a %gamma_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %gamma_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ gamma_distribution<_RealType>& __x);
+
+
+ /**
+ * @brief A weibull_distribution random number distribution.
+ *
+ * The formula for the normal probability density function is
+ * @f$ p(x|\alpha,\beta) = \frac{a}{b} (frac{x}{b})^{a-1}
+ * \exp{(-(frac{x}{b})^a)} @f$.
+ */
+ template<typename _RealType = double>
+ class weibull_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef weibull_distribution<_RealType> distribution_type;
+
+ explicit
+ param_type(_RealType __a = _RealType(1),
+ _RealType __b = _RealType(1))
+ : _M_a(__a), _M_b(__b)
+ { }
+
+ _RealType
+ a() const
+ { return _M_a; }
+
+ _RealType
+ b() const
+ { return _M_b; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_a == __p2._M_a) && (__p1._M_b == __p2._M_b); }
+
+ private:
+ _RealType _M_a;
+ _RealType _M_b;
+ };
+
+ explicit
+ weibull_distribution(_RealType __a = _RealType(1),
+ _RealType __b = _RealType(1))
+ : _M_param(__a, __b)
+ { }
+
+ explicit
+ weibull_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ */
+ void
+ reset()
+ { }
+
+ /**
+ * @brief Return the @f$ a @f$ parameter of the distribution.
+ */
+ _RealType
+ a() const
+ { return _M_param.a(); }
+
+ /**
+ * @brief Return the @f$ b @f$ parameter of the distribution.
+ */
+ _RealType
+ b() const
+ { return _M_param.b(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return result_type(0); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+ return __p.b() * std::pow(-std::log(__aurng()),
+ result_type(1) / __p.a());
+ }
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ * @brief Return true if two Weibull distributions have the same
+ * parameters.
+ */
+ template<typename _RealType>
+ bool
+ operator==(const weibull_distribution<_RealType>& __d1,
+ const weibull_distribution<_RealType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %weibull_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %weibull_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const weibull_distribution<_RealType>& __x);
+
+ /**
+ * @brief Extracts a %weibull_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %weibull_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ weibull_distribution<_RealType>& __x);
+
+
+ /**
+ * @brief A extreme_value_distribution random number distribution.
+ *
+ * The formula for the normal probability mass function is
+ * @f$ p(x|a,b) = \frac{1}{b}
+ * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b})) @f$
+ */
+ template<typename _RealType = double>
+ class extreme_value_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef extreme_value_distribution<_RealType> distribution_type;
+
+ explicit
+ param_type(_RealType __a = _RealType(0),
+ _RealType __b = _RealType(1))
+ : _M_a(__a), _M_b(__b)
+ { }
+
+ _RealType
+ a() const
+ { return _M_a; }
+
+ _RealType
+ b() const
+ { return _M_b; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_a == __p2._M_a) && (__p1._M_b == __p2._M_b); }
+
+ private:
+ _RealType _M_a;
+ _RealType _M_b;
+ };
+
+ explicit
+ extreme_value_distribution(_RealType __a = _RealType(0),
+ _RealType __b = _RealType(1))
+ : _M_param(__a, __b)
+ { }
+
+ explicit
+ extreme_value_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ */
+ void
+ reset()
+ { }
+
+ /**
+ * @brief Return the @f$ a @f$ parameter of the distribution.
+ */
+ _RealType
+ a() const
+ { return _M_param.a(); }
+
+ /**
+ * @brief Return the @f$ b @f$ parameter of the distribution.
+ */
+ _RealType
+ b() const
+ { return _M_param.b(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return std::numeric_limits<result_type>::min(); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ *
+ */
+ template<typename _RealType>
+ bool
+ operator==(const extreme_value_distribution<_RealType>& __d1,
+ const extreme_value_distribution<_RealType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /**
+ * @brief Inserts a %extreme_value_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %extreme_value_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const extreme_value_distribution<_RealType>& __x);
+
+ /**
+ * @brief Extracts a %extreme_value_distribution random number
+ * distribution @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %extreme_value_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ extreme_value_distribution<_RealType>& __x);
+
+
+ /**
+ * @brief A discrete_distribution random number distribution.
+ *
+ * The formula for the discrete probability mass function is
+ *
+ */
+ template<typename _IntType = int>
+ class discrete_distribution
+ {
+ __glibcxx_class_requires(_IntType, _IntegerConcept)
+
+ public:
+ /** The type of the range of the distribution. */
+ typedef _IntType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef discrete_distribution<_IntType> distribution_type;
+ friend class discrete_distribution<_IntType>;
+
+ param_type()
+ : _M_prob(), _M_cp()
+ { _M_initialize(); }
+
+ template<typename _InputIterator>
+ param_type(_InputIterator __wbegin,
+ _InputIterator __wend)
+ : _M_prob(__wbegin, __wend), _M_cp()
+ { _M_initialize(); }
+
+ param_type(initializer_list<double> __wil)
+ : _M_prob(__wil.begin(), __wil.end()), _M_cp()
+ { _M_initialize(); }
+
+ template<typename _Func>
+ param_type(size_t __nw, double __xmin, double __xmax,
+ _Func __fw);
+
+ std::vector<double>
+ probabilities() const
+ { return _M_prob; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return __p1._M_prob == __p2._M_prob; }
+
+ private:
+ void
+ _M_initialize();
+
+ std::vector<double> _M_prob;
+ std::vector<double> _M_cp;
+ };
+
+ discrete_distribution()
+ : _M_param()
+ { }
+
+ template<typename _InputIterator>
+ discrete_distribution(_InputIterator __wbegin,
+ _InputIterator __wend)
+ : _M_param(__wbegin, __wend)
+ { }
+
+ discrete_distribution(initializer_list<double> __wil)
+ : _M_param(__wil)
+ { }
+
+ template<typename _Func>
+ discrete_distribution(size_t __nw, double __xmin, double __xmax,
+ _Func __fw)
+ : _M_param(__nw, __xmin, __xmax, __fw)
+ { }
+
+ explicit
+ discrete_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ */
+ void
+ reset()
+ { }
+
+ /**
+ * @brief Returns the probabilities of the distribution.
+ */
+ std::vector<double>
+ probabilities() const
+ { return _M_param.probabilities(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return result_type(0); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return this->_M_param._M_prob.size() - 1; }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ /**
+ * @brief Inserts a %discrete_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %discrete_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _IntType1, typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const discrete_distribution<_IntType1>& __x);
+
+ /**
+ * @brief Extracts a %discrete_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %discrete_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error
+ * state.
+ */
+ template<typename _IntType1, typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ discrete_distribution<_IntType1>& __x);
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ *
+ */
+ template<typename _IntType>
+ bool
+ operator==(const discrete_distribution<_IntType>& __d1,
+ const discrete_distribution<_IntType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+
+ /**
+ * @brief A piecewise_constant_distribution random number distribution.
+ *
+ * The formula for the piecewise constant probability mass function is
+ *
+ */
+ template<typename _RealType = double>
+ class piecewise_constant_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef piecewise_constant_distribution<_RealType> distribution_type;
+ friend class piecewise_constant_distribution<_RealType>;
+
+ param_type();
+
+ template<typename _InputIteratorB, typename _InputIteratorW>
+ param_type(_InputIteratorB __bfirst,
+ _InputIteratorB __bend,
+ _InputIteratorW __wbegin);
+
+ template<typename _Func>
+ param_type(initializer_list<_RealType> __bil, _Func __fw);
+
+ template<typename _Func>
+ param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
+ _Func __fw);
+
+ std::vector<_RealType>
+ intervals() const
+ { return _M_int; }
+
+ std::vector<double>
+ densities() const
+ { return _M_den; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_int == __p2._M_int)
+ && (__p1._M_den == __p2._M_den); }
+
+ private:
+ void
+ _M_initialize();
+
+ std::vector<_RealType> _M_int;
+ std::vector<double> _M_den;
+ std::vector<double> _M_cp;
+ };
+
+ explicit
+ piecewise_constant_distribution()
+ : _M_param()
+ { }
+
+ template<typename _InputIteratorB, typename _InputIteratorW>
+ piecewise_constant_distribution(_InputIteratorB __bfirst,
+ _InputIteratorB __bend,
+ _InputIteratorW __wbegin)
+ : _M_param(__bfirst, __bend, __wbegin)
+ { }
+
+ template<typename _Func>
+ piecewise_constant_distribution(initializer_list<_RealType> __bil,
+ _Func __fw)
+ : _M_param(__bil, __fw)
+ { }
+
+ template<typename _Func>
+ piecewise_constant_distribution(size_t __nw,
+ _RealType __xmin, _RealType __xmax,
+ _Func __fw)
+ : _M_param(__nw, __xmin, __xmax, __fw)
+ { }
+
+ explicit
+ piecewise_constant_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * @brief Resets the distribution state.
+ */
+ void
+ reset()
+ { }
+
+ /**
+ * @brief Returns a vector of the intervals.
+ */
+ std::vector<_RealType>
+ intervals() const
+ { return _M_param.intervals(); }
+
+ /**
+ * @brief Returns a vector of the probability densities.
+ */
+ std::vector<double>
+ densities() const
+ { return _M_param.densities(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return this->_M_param._M_int.front(); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return this->_M_param._M_int.back(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ /**
+ * @brief Inserts a %piecewise_constan_distribution random
+ * number distribution @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %piecewise_constan_distribution random number
+ * distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType1, typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const piecewise_constant_distribution<_RealType1>& __x);
+
+ /**
+ * @brief Extracts a %piecewise_constan_distribution random
+ * number distribution @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %piecewise_constan_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error
+ * state.
+ */
+ template<typename _RealType1, typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ piecewise_constant_distribution<_RealType1>& __x);
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ *
+ */
+ template<typename _RealType>
+ bool
+ operator==(const piecewise_constant_distribution<_RealType>& __d1,
+ const piecewise_constant_distribution<_RealType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+
+ /**
+ * @brief A piecewise_linear_distribution random number distribution.
+ *
+ * The formula for the piecewise linear probability mass function is
+ *
+ */
+ template<typename _RealType = double>
+ class piecewise_linear_distribution
+ {
+ public:
+ /** The type of the range of the distribution. */
+ typedef _RealType result_type;
+ /** Parameter type. */
+ struct param_type
+ {
+ typedef piecewise_linear_distribution<_RealType> distribution_type;
+ friend class piecewise_linear_distribution<_RealType>;
+
+ param_type();
+
+ template<typename _InputIteratorB, typename _InputIteratorW>
+ param_type(_InputIteratorB __bfirst,
+ _InputIteratorB __bend,
+ _InputIteratorW __wbegin);
+
+ template<typename _Func>
+ param_type(initializer_list<_RealType> __bil, _Func __fw);
+
+ template<typename _Func>
+ param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
+ _Func __fw);
+
+ std::vector<_RealType>
+ intervals() const
+ { return _M_int; }
+
+ std::vector<double>
+ densities() const
+ { return _M_den; }
+
+ friend bool
+ operator==(const param_type& __p1, const param_type& __p2)
+ { return (__p1._M_int == __p2._M_int)
+ && (__p1._M_den == __p2._M_den); }
+
+ private:
+ void
+ _M_initialize();
+
+ std::vector<_RealType> _M_int;
+ std::vector<double> _M_den;
+ std::vector<double> _M_cp;
+ std::vector<double> _M_m;
+ };
+
+ explicit
+ piecewise_linear_distribution()
+ : _M_param()
+ { }
+
+ template<typename _InputIteratorB, typename _InputIteratorW>
+ piecewise_linear_distribution(_InputIteratorB __bfirst,
+ _InputIteratorB __bend,
+ _InputIteratorW __wbegin)
+ : _M_param(__bfirst, __bend, __wbegin)
+ { }
+
+ template<typename _Func>
+ piecewise_linear_distribution(initializer_list<_RealType> __bil,
+ _Func __fw)
+ : _M_param(__bil, __fw)
+ { }
+
+ template<typename _Func>
+ piecewise_linear_distribution(size_t __nw,
+ _RealType __xmin, _RealType __xmax,
+ _Func __fw)
+ : _M_param(__nw, __xmin, __xmax, __fw)
+ { }
+
+ explicit
+ piecewise_linear_distribution(const param_type& __p)
+ : _M_param(__p)
+ { }
+
+ /**
+ * Resets the distribution state.
+ */
+ void
+ reset()
+ { }
+
+ /**
+ * @brief Return the intervals of the distribution.
+ */
+ std::vector<_RealType>
+ intervals() const
+ { return _M_param.intervals(); }
+
+ /**
+ * @brief Return a vector of the probability densities of the
+ * distribution.
+ */
+ std::vector<double>
+ densities() const
+ { return _M_param.densities(); }
+
+ /**
+ * @brief Returns the parameter set of the distribution.
+ */
+ param_type
+ param() const
+ { return _M_param; }
+
+ /**
+ * @brief Sets the parameter set of the distribution.
+ * @param __param The new parameter set of the distribution.
+ */
+ void
+ param(const param_type& __param)
+ { _M_param = __param; }
+
+ /**
+ * @brief Returns the greatest lower bound value of the distribution.
+ */
+ result_type
+ min() const
+ { return this->_M_param._M_int.front(); }
+
+ /**
+ * @brief Returns the least upper bound value of the distribution.
+ */
+ result_type
+ max() const
+ { return this->_M_param._M_int.back(); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return this->operator()(__urng, this->param()); }
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
+ /**
+ * @brief Inserts a %piecewise_linear_distribution random number
+ * distribution @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %piecewise_linear_distribution random number
+ * distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType1, typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const piecewise_linear_distribution<_RealType1>& __x);
+
+ /**
+ * @brief Extracts a %piecewise_linear_distribution random number
+ * distribution @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %piecewise_linear_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error
+ * state.
+ */
+ template<typename _RealType1, typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ piecewise_linear_distribution<_RealType1>& __x);
+
+ private:
+ param_type _M_param;
+ };
+
+ /**
+ *
+ */
+ template<typename _RealType>
+ bool
+ operator==(const piecewise_linear_distribution<_RealType>& __d1,
+ const piecewise_linear_distribution<_RealType>& __d2)
+ { return __d1.param() == __d2.param(); }
+
+ /* @} */ // group std_random_distributions_poisson
+
+ /* @} */ // group std_random_distributions
+
+ /**
+ * @addtogroup std_random_utilities Random Number Utilities
+ * @ingroup std_random
+ * @{
+ */
+
+ /**
+ * @brief The seed_seq class generates sequences of seeds for random
+ * number generators.
+ */
+ class seed_seq
+ {
+
+ public:
+ /** The type of the seed vales. */
+ typedef uint_least32_t result_type;
+
+ /** Default constructor. */
+ seed_seq()
+ : _M_v()
+ { }
+
+ template<typename _IntType>
+ seed_seq(std::initializer_list<_IntType> il);
+
+ template<typename _InputIterator>
+ seed_seq(_InputIterator __begin, _InputIterator __end);
+
+ // generating functions
+ template<typename _RandomAccessIterator>
+ void
+ generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
+
+ // property functions
+ size_t size() const
+ { return _M_v.size(); }
+
+ template<typename OutputIterator>
+ void
+ param(OutputIterator __dest) const
+ { std::copy(_M_v.begin(), _M_v.end(), __dest); }
+
+ private:
+ ///
+ vector<result_type> _M_v;
+ };
+
+ /* @} */ // group std_random_utilities
+
+ /* @} */ // group std_random
+
+}
+
diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc
new file mode 100644
index 00000000000..0c4f7a4420d
--- /dev/null
+++ b/libstdc++-v3/include/bits/random.tcc
@@ -0,0 +1,2794 @@
+// random number generation (out of line) -*- C++ -*-
+
+// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/** @file bits/random.tcc
+ * This is an internal header file, included by other library headers.
+ * You should not attempt to use it directly.
+ */
+
+#include <iostream>
+#include <vector>
+#include <numeric>
+#include <algorithm>
+
+namespace std
+{
+
+ /*
+ * (Further) implementation-space details.
+ */
+ namespace __detail
+ {
+ // General case for x = (ax + c) mod m -- use Schrage's algorithm to
+ // avoid integer overflow.
+ //
+ // Because a and c are compile-time integral constants the compiler
+ // kindly elides any unreachable paths.
+ //
+ // Preconditions: a > 0, m > 0.
+ //
+ template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool>
+ struct _Mod
+ {
+ static _Tp
+ __calc(_Tp __x)
+ {
+ if (__a == 1)
+ __x %= __m;
+ else
+ {
+ static const _Tp __q = __m / __a;
+ static const _Tp __r = __m % __a;
+
+ _Tp __t1 = __a * (__x % __q);
+ _Tp __t2 = __r * (__x / __q);
+ if (__t1 >= __t2)
+ __x = __t1 - __t2;
+ else
+ __x = __m - __t2 + __t1;
+ }
+
+ if (__c != 0)
+ {
+ const _Tp __d = __m - __x;
+ if (__d > __c)
+ __x += __c;
+ else
+ __x = __c - __d;
+ }
+ return __x;
+ }
+ };
+
+ // Special case for m == 0 -- use unsigned integer overflow as modulo
+ // operator.
+ template<typename _Tp, _Tp __a, _Tp __c, _Tp __m>
+ struct _Mod<_Tp, __a, __c, __m, true>
+ {
+ static _Tp
+ __calc(_Tp __x)
+ { return __a * __x + __c; }
+ };
+ } // namespace __detail
+
+ /**
+ * Seeds the LCR with integral value @p __x0, adjusted so that the
+ * ring identity is never a member of the convergence set.
+ */
+ template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+ void
+ linear_congruential_engine<_UIntType, __a, __c, __m>::
+ seed(_UIntType __x0)
+ {
+ if ((__detail::__mod<_UIntType, 1U, 0U, __m>(__c) == 0U)
+ && (__detail::__mod<_UIntType, 1U, 0U, __m>(__x0) == 0U))
+ _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(1U);
+ else
+ _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(__x0);
+ }
+
+ /**
+ * Seeds the LCR engine with a value generated by @p __g.
+ */
+ template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+ void
+ linear_congruential_engine<_UIntType, __a, __c, __m>::
+ seed(seed_seq& __q)
+ {
+ const _UIntType __k = (std::log2(__m) + 31) / 32;
+ _UIntType __arr[__k + 3];
+ __q.generate(__arr + 0, __arr + 3);
+ _UIntType __factor = 1U;
+ _UIntType __sum = 0U;
+ for (size_t __i = 0; __i < __k; ++__i)
+ {
+ __sum += __arr[__i + 3] * __factor;
+ __factor *= __detail::_Shift<_UIntType, 32>::__value;
+ }
+
+ if ((__detail::__mod<_UIntType, 1U, 0U, __m>(__c) == 0U)
+ && (__detail::__mod<_UIntType, 1U, 0U, __m>(__sum) == 0U))
+ _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(1U);
+ else
+ _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(__sum);
+ }
+
+ /**
+ * Seeds the LCR engine with a value generated by @p __g.
+ */
+ template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+ template<typename _Gen>
+ void
+ linear_congruential_engine<_UIntType, __a, __c, __m>::
+ seed(_Gen& __g, false_type)
+ {
+ _UIntType __x0 = __g();
+ if ((__detail::__mod<_UIntType, 1U, 0U, __m>(__c) == 0U)
+ && (__detail::__mod<_UIntType, 1U, 0U, __m>(__x0) == 0U))
+ _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(1U);
+ else
+ _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(__x0);
+ }
+
+ /**
+ * Gets the next generated value in sequence.
+ */
+ template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+ typename linear_congruential_engine<_UIntType, __a, __c, __m>::
+ result_type
+ linear_congruential_engine<_UIntType, __a, __c, __m>::
+ operator()()
+ {
+ _M_x = __detail::__mod<_UIntType, __a, __c, __m>(_M_x);
+ return _M_x;
+ }
+
+ template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const linear_congruential_engine<_UIntType,
+ __a, __c, __m>& __lcr)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ __os.flags(__ios_base::dec
+ | __ios_base::fixed
+ | __ios_base::left);
+ __os.fill(__os.widen(' '));
+
+ __os << __lcr._M_x;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ linear_congruential_engine<_UIntType, __a, __c, __m>& __lcr)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec);
+
+ __is >> __lcr._M_x;
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _UIntType,
+ size_t __w, size_t __n, size_t __m, size_t __r,
+ _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+ _UIntType __b, size_t __t, _UIntType __c, size_t __l,
+ _UIntType __f>
+ void
+ mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
+ __s, __b, __t, __c, __l, __f>::
+ seed(result_type __sd)
+ {
+ _M_x[0] = __detail::__mod<_UIntType, 1, 0,
+ __detail::_Shift<_UIntType, __w>::__value>(__sd);
+
+ for (size_t __i = 1; __i < state_size; ++__i)
+ {
+ _UIntType __x = _M_x[__i - 1];
+ __x ^= __x >> (__w - 2);
+ __x *= __f;
+ __x += __i;
+ _M_x[__i] = __detail::__mod<_UIntType, 1, 0,
+ __detail::_Shift<_UIntType, __w>::__value>(__x);
+ }
+ _M_p = state_size;
+ }
+
+ template<typename _UIntType,
+ size_t __w, size_t __n, size_t __m, size_t __r,
+ _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+ _UIntType __b, size_t __t, _UIntType __c, size_t __l,
+ _UIntType __f>
+ void
+ mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
+ __s, __b, __t, __c, __l, __f>::
+ seed(seed_seq& __q)
+ {
+ const _UIntType __upper_mask = (~_UIntType()) << __r;
+ const size_t __k = (__w + 31) / 32;
+ _UIntType __arr[__k * __n];
+ __q.generate(__arr + 0, __arr + __k * __n);
+
+ bool __zero = true;
+ for (size_t __i = 0; __i < state_size; ++__i)
+ {
+ _UIntType __factor = 1U;
+ _UIntType __sum = 0U;
+ for (size_t __j = 0; __j < __k; ++__j)
+ {
+ __sum += __arr[__i * __k + __j] * __factor;
+ __factor *= __detail::_Shift<_UIntType, 32>::__value;
+ }
+ _M_x[__i] = __detail::__mod<_UIntType, 1U, 0U,
+ __detail::_Shift<_UIntType, __w>::__value>(__sum);
+
+ if (__zero)
+ {
+ if (__i == 0)
+ {
+ if ((_M_x[0] & __upper_mask) != 0U)
+ __zero = false;
+ }
+ else if (_M_x[__i] != 0U)
+ __zero = false;
+ }
+ }
+ if (__zero)
+ _M_x[0] = __detail::_Shift<_UIntType, __w - 1U>::__value;
+ }
+
+ template<typename _UIntType, size_t __w,
+ size_t __n, size_t __m, size_t __r,
+ _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+ _UIntType __b, size_t __t, _UIntType __c, size_t __l,
+ _UIntType __f>
+ typename
+ mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
+ __s, __b, __t, __c, __l, __f>::result_type
+ mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
+ __s, __b, __t, __c, __l, __f>::
+ operator()()
+ {
+ // Reload the vector - cost is O(n) amortized over n calls.
+ if (_M_p >= state_size)
+ {
+ const _UIntType __upper_mask = (~_UIntType()) << __r;
+ const _UIntType __lower_mask = ~__upper_mask;
+
+ for (size_t __k = 0; __k < (__n - __m); ++__k)
+ {
+ _UIntType __y = ((_M_x[__k] & __upper_mask)
+ | (_M_x[__k + 1] & __lower_mask));
+ _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
+ ^ ((__y & 0x01) ? __a : 0));
+ }
+
+ for (size_t __k = (__n - __m); __k < (__n - 1); ++__k)
+ {
+ _UIntType __y = ((_M_x[__k] & __upper_mask)
+ | (_M_x[__k + 1] & __lower_mask));
+ _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
+ ^ ((__y & 0x01) ? __a : 0));
+ }
+
+ _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
+ | (_M_x[0] & __lower_mask));
+ _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
+ ^ ((__y & 0x01) ? __a : 0));
+ _M_p = 0;
+ }
+
+ // Calculate o(x(i)).
+ result_type __z = _M_x[_M_p++];
+ __z ^= (__z >> __u) & __d;
+ __z ^= (__z << __s) & __b;
+ __z ^= (__z << __t) & __c;
+ __z ^= (__z >> __l);
+
+ return __z;
+ }
+
+ template<typename _UIntType, size_t __w,
+ size_t __n, size_t __m, size_t __r,
+ _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+ _UIntType __b, size_t __t, _UIntType __c, size_t __l,
+ _UIntType __f, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const mersenne_twister_engine<_UIntType, __w, __n, __m,
+ __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::dec
+ | __ios_base::fixed
+ | __ios_base::left);
+ __os.fill(__space);
+
+ for (size_t __i = 0; __i < __n - 1; ++__i)
+ __os << __x._M_x[__i] << __space;
+ __os << __x._M_x[__n - 1];
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<typename _UIntType, size_t __w,
+ size_t __n, size_t __m, size_t __r,
+ _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+ _UIntType __b, size_t __t, _UIntType __c, size_t __l,
+ _UIntType __f, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ mersenne_twister_engine<_UIntType, __w, __n, __m,
+ __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ for (size_t __i = 0; __i < __n; ++__i)
+ __is >> __x._M_x[__i];
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _UIntType, size_t __w, size_t __s, size_t __r>
+ void
+ subtract_with_carry_engine<_UIntType, __w, __s, __r>::
+ seed(result_type __value)
+ {
+ if (__value == 0)
+ __value = default_seed;
+
+ std::linear_congruential_engine<result_type, 40014U, 0U, 2147483563U>
+ __lcg(__value);
+
+ // I hope this is right. The "10000" tests work for the ranluxen.
+ const size_t __n = (word_size + 31) / 32;
+
+ for (size_t __i = 0; __i < long_lag; ++__i)
+ {
+ _UIntType __sum = 0U;
+ _UIntType __factor = 1U;
+ for (size_t __j = 0; __j < __n; ++__j)
+ {
+ __sum += __detail::__mod<__detail::_UInt32Type, 1, 0, 0>
+ (__lcg()) * __factor;
+ __factor *= __detail::_Shift<_UIntType, 32>::__value;
+ }
+ _M_x[__i] = __detail::__mod<_UIntType, 1, 0, _S_modulus>(__sum);
+ }
+ _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
+ _M_p = 0;
+ }
+
+ template<typename _UIntType, size_t __w, size_t __s, size_t __r>
+ void
+ subtract_with_carry_engine<_UIntType, __w, __s, __r>::
+ seed(seed_seq& __q)
+ {
+ const size_t __n = (word_size + 31) / 32;
+ unsigned int __arr[long_lag + __n];
+ __q.generate(__arr + 0, __arr + long_lag + __n);
+
+ for (size_t __i = 0; __i < long_lag; ++__i)
+ {
+ _UIntType __sum = 0U;
+ _UIntType __factor = 1U;
+ for (size_t __j = 0; __j < __n; ++__j)
+ {
+ __sum += __detail::__mod<__detail::_UInt32Type, 1, 0, 0>
+ (__arr[__i * __n + __j]) * __factor;
+ __factor *= __detail::_Shift<_UIntType, 32>::__value;
+ }
+ _M_x[__i] = __detail::__mod<_UIntType, 1, 0, _S_modulus>(__sum);
+ }
+ _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
+ _M_p = 0;
+ }
+
+ template<typename _UIntType, size_t __w, size_t __s, size_t __r>
+ typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::
+ result_type
+ subtract_with_carry_engine<_UIntType, __w, __s, __r>::
+ operator()()
+ {
+ // Derive short lag index from current index.
+ long __ps = _M_p - short_lag;
+ if (__ps < 0)
+ __ps += long_lag;
+
+ // Calculate new x(i) without overflow or division.
+ // NB: Thanks to the requirements for _UIntType, _M_x[_M_p] + _M_carry
+ // cannot overflow.
+ _UIntType __xi;
+ if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
+ {
+ __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
+ _M_carry = 0;
+ }
+ else
+ {
+ __xi = _S_modulus - _M_x[_M_p] - _M_carry + _M_x[__ps];
+ _M_carry = 1;
+ }
+ _M_x[_M_p] = __xi;
+
+ // Adjust current index to loop around in ring buffer.
+ if (++_M_p >= long_lag)
+ _M_p = 0;
+
+ return __xi;
+ }
+
+ template<typename _UIntType, size_t __w, size_t __s, size_t __r,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const subtract_with_carry_engine<_UIntType,
+ __w, __s, __r>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::dec
+ | __ios_base::fixed
+ | __ios_base::left);
+ __os.fill(__space);
+
+ for (size_t __i = 0; __i < __r; ++__i)
+ __os << __x._M_x[__i] << __space;
+ __os << __x._M_carry;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<typename _UIntType, size_t __w, size_t __s, size_t __r,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ subtract_with_carry_engine<_UIntType, __w, __s, __r>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ for (size_t __i = 0; __i < __r; ++__i)
+ __is >> __x._M_x[__i];
+ __is >> __x._M_carry;
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RandomNumberEngine, size_t __p, size_t __r>
+ typename discard_block_engine<_RandomNumberEngine,
+ __p, __r>::result_type
+ discard_block_engine<_RandomNumberEngine, __p, __r>::
+ operator()()
+ {
+ if (_M_n >= used_block)
+ {
+ _M_b.discard(block_size - _M_n);
+ _M_n = 0;
+ }
+ ++_M_n;
+ return _M_b();
+ }
+
+ template<typename _RandomNumberEngine, size_t __p, size_t __r,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const discard_block_engine<_RandomNumberEngine,
+ __p, __r>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::dec
+ | __ios_base::fixed
+ | __ios_base::left);
+ __os.fill(__space);
+
+ __os << __x.base() << __space << __x._M_n;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<typename _RandomNumberEngine, size_t __p, size_t __r,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ discard_block_engine<_RandomNumberEngine, __p, __r>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ __is >> __x._M_b >> __x._M_n;
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
+ typename independent_bits_engine<_RandomNumberEngine, __w, _UIntType>::
+ result_type
+ independent_bits_engine<_RandomNumberEngine, __w, _UIntType>::
+ operator()()
+ {
+ const long double __r = static_cast<long double>(this->max())
+ - static_cast<long double>(this->min()) + 1.0L;
+ const result_type __m = std::log2l(__r);
+ result_type __n, __n0, __y0, __y1, __s0, __s1;
+ for (size_t __i = 0; __i < 2; ++__i)
+ {
+ __n = (__w + __m - 1) / __m + __i;
+ __n0 = __n - __w % __n;
+ const result_type __w0 = __w / __n;
+ const result_type __w1 = __w0 + 1;
+ __s0 = 1UL << __w0;
+ __s1 = 1UL << __w1;
+ __y0 = __s0 * (__r / __s0);
+ __y1 = __s1 * (__r / __s1);
+ if (__r - __y0 <= __y0 / __n)
+ break;
+ }
+
+ result_type __sum = 0;
+ for (size_t __k = 0; __k < __n0; ++__k)
+ {
+ result_type __u;
+ do
+ __u = _M_b() - this->min();
+ while (__u >= __y0);
+ __sum = __s0 * __sum
+ + __u % __s0;
+ }
+ for (size_t __k = __n0; __k < __n; ++__k)
+ {
+ result_type __u;
+ do
+ __u = _M_b() - this->min();
+ while (__u >= __y1);
+ __sum = __s1 * __sum
+ + __u % __s1;
+ }
+ return __sum;
+ }
+
+
+ template<typename _RandomNumberEngine, size_t __k>
+ typename shuffle_order_engine<_RandomNumberEngine, __k>::result_type
+ shuffle_order_engine<_RandomNumberEngine, __k>::
+ operator()()
+ {
+ size_t __j = (__k * (_M_y - _M_b.min()))
+ / (_M_b.max() - _M_b.min() + 1);
+ _M_y = _M_v[__j];
+ _M_v[__j] = _M_b();
+
+ return _M_y;
+ }
+
+ template<typename _RandomNumberEngine, size_t __k,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const shuffle_order_engine<_RandomNumberEngine, __k>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::dec
+ | __ios_base::fixed
+ | __ios_base::left);
+ __os.fill(__space);
+
+ __os << __x.base();
+ for (size_t __i = 0; __i < __k; ++__i)
+ __os << __space << __x._M_v[__i];
+ __os << __space << __x._M_y;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<typename _RandomNumberEngine, size_t __k,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ shuffle_order_engine<_RandomNumberEngine, __k>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ __is >> __x._M_b;
+ for (size_t __i = 0; __i < __k; ++__i)
+ __is >> __x._M_v[__i];
+ __is >> __x._M_y;
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _IntType>
+ template<typename _UniformRandomNumberGenerator>
+ typename uniform_int_distribution<_IntType>::result_type
+ uniform_int_distribution<_IntType>::
+ _M_call(_UniformRandomNumberGenerator& __urng,
+ result_type __min, result_type __max, true_type)
+ {
+ // XXX Must be fixed to work well for *arbitrary* __urng.max(),
+ // __urng.min(), __max, __min. Currently works fine only in the
+ // most common case __urng.max() - __urng.min() >= __max - __min,
+ // with __urng.max() > __urng.min() >= 0.
+ typedef typename __gnu_cxx::__add_unsigned<typename
+ _UniformRandomNumberGenerator::result_type>::__type __urntype;
+ typedef typename __gnu_cxx::__add_unsigned<result_type>::__type
+ __utype;
+ typedef typename __gnu_cxx::__conditional_type<(sizeof(__urntype)
+ > sizeof(__utype)),
+ __urntype, __utype>::__type __uctype;
+
+ result_type __ret;
+
+ const __urntype __urnmin = __urng.min();
+ const __urntype __urnmax = __urng.max();
+ const __urntype __urnrange = __urnmax - __urnmin;
+ const __uctype __urange = __max - __min;
+ const __uctype __udenom = (__urnrange <= __urange
+ ? 1 : __urnrange / (__urange + 1));
+ do
+ __ret = (__urntype(__urng()) - __urnmin) / __udenom;
+ while (__ret > __max - __min);
+
+ return __ret + __min;
+ }
+
+ template<typename _IntType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const uniform_int_distribution<_IntType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+
+ __os << __x.a() << __space << __x.b();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<typename _IntType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ uniform_int_distribution<_IntType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ _IntType __a, __b;
+ __is >> __a >> __b;
+ __x.param(typename uniform_int_distribution<_IntType>::
+ param_type(__a, __b));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const uniform_real_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ __os << __x.a() << __space << __x.b();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ uniform_real_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::skipws);
+
+ _RealType __a, __b;
+ __is >> __a >> __b;
+ __x.param(typename uniform_real_distribution<_RealType>::
+ param_type(__a, __b));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const bernoulli_distribution& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__os.widen(' '));
+ __os.precision(std::numeric_limits<double>::digits10 + 1);
+
+ __os << __x.p();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+
+ template<typename _IntType>
+ template<typename _UniformRandomNumberGenerator>
+ typename geometric_distribution<_IntType>::result_type
+ geometric_distribution<_IntType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ // About the epsilon thing see this thread:
+ // http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00971.html
+ const double __naf =
+ (1 - std::numeric_limits<double>::epsilon()) / 2;
+ // The largest _RealType convertible to _IntType.
+ const double __thr =
+ std::numeric_limits<_IntType>::max() + __naf;
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+
+ double __cand;
+ do
+ __cand = std::ceil(std::log(__aurng()) / __param._M_log_p);
+ while (__cand >= __thr);
+
+ return result_type(__cand + __naf);
+ }
+
+ template<typename _IntType,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const geometric_distribution<_IntType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__os.widen(' '));
+ __os.precision(std::numeric_limits<double>::digits10 + 1);
+
+ __os << __x.p();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _IntType,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ geometric_distribution<_IntType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::skipws);
+
+ double __p;
+ __is >> __p;
+ __x.param(typename geometric_distribution<_IntType>::param_type(__p));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+ template<typename _IntType>
+ template<typename _UniformRandomNumberGenerator>
+ typename negative_binomial_distribution<_IntType>::result_type
+ negative_binomial_distribution<_IntType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ typename gamma_distribution<>::param_type
+ __gamma_param(__p.k(), 1.0);
+ gamma_distribution<> __gamma(__gamma_param);
+ double __x = __gamma(__urng);
+
+ typename poisson_distribution<result_type>::param_type
+ __poisson_param(__x * __p.p() / (1.0 - __p.p()));
+ poisson_distribution<result_type> __poisson(__poisson_param);
+ result_type __m = __poisson(__urng);
+
+ return __m;
+ }
+
+ template<typename _IntType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const negative_binomial_distribution<_IntType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__os.widen(' '));
+ __os.precision(std::numeric_limits<double>::digits10 + 1);
+
+ __os << __x.k() << __space << __x.p();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _IntType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ negative_binomial_distribution<_IntType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::skipws);
+
+ _IntType __k;
+ double __p;
+ __is >> __k >> __p;
+ __x.param(typename negative_binomial_distribution<_IntType>::
+ param_type(__k, __p));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _IntType>
+ void
+ poisson_distribution<_IntType>::param_type::
+ _M_initialize()
+ {
+#if _GLIBCXX_USE_C99_MATH_TR1
+ if (_M_mean >= 12)
+ {
+ const double __m = std::floor(_M_mean);
+ _M_lm_thr = std::log(_M_mean);
+ _M_lfm = std::lgamma(__m + 1);
+ _M_sm = std::sqrt(__m);
+
+ const double __pi_4 = 0.7853981633974483096156608458198757L;
+ const double __dx = std::sqrt(2 * __m * std::log(32 * __m
+ / __pi_4));
+ _M_d = std::round(std::max(6.0, std::min(__m, __dx)));
+ const double __cx = 2 * __m + _M_d;
+ _M_scx = std::sqrt(__cx / 2);
+ _M_1cx = 1 / __cx;
+
+ _M_c2b = std::sqrt(__pi_4 * __cx) * std::exp(_M_1cx);
+ _M_cb = 2 * __cx * std::exp(-_M_d * _M_1cx * (1 + _M_d / 2))
+ / _M_d;
+ }
+ else
+#endif
+ _M_lm_thr = std::exp(-_M_mean);
+ }
+
+ /**
+ * A rejection algorithm when mean >= 12 and a simple method based
+ * upon the multiplication of uniform random variates otherwise.
+ * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1
+ * is defined.
+ *
+ * Reference:
+ * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag,
+ * New York, 1986, Ch. X, Sects. 3.3 & 3.4 (+ Errata!).
+ */
+ template<typename _IntType>
+ template<typename _UniformRandomNumberGenerator>
+ typename poisson_distribution<_IntType>::result_type
+ poisson_distribution<_IntType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
+ __aurng(__urng);
+#if _GLIBCXX_USE_C99_MATH_TR1
+ if (__param.mean() >= 12)
+ {
+ double __x;
+
+ // See comments above...
+ const double __naf =
+ (1 - std::numeric_limits<double>::epsilon()) / 2;
+ const double __thr =
+ std::numeric_limits<_IntType>::max() + __naf;
+
+ const double __m = std::floor(__param.mean());
+ // sqrt(pi / 2)
+ const double __spi_2 = 1.2533141373155002512078826424055226L;
+ const double __c1 = __param._M_sm * __spi_2;
+ const double __c2 = __param._M_c2b + __c1;
+ const double __c3 = __c2 + 1;
+ const double __c4 = __c3 + 1;
+ // e^(1 / 78)
+ const double __e178 = 1.0129030479320018583185514777512983L;
+ const double __c5 = __c4 + __e178;
+ const double __c = __param._M_cb + __c5;
+ const double __2cx = 2 * (2 * __m + __param._M_d);
+
+ bool __reject = true;
+ do
+ {
+ const double __u = __c * __aurng();
+ const double __e = -std::log(__aurng());
+
+ double __w = 0.0;
+
+ if (__u <= __c1)
+ {
+ const double __n = _M_nd(__urng);
+ const double __y = -std::abs(__n) * __param._M_sm - 1;
+ __x = std::floor(__y);
+ __w = -__n * __n / 2;
+ if (__x < -__m)
+ continue;
+ }
+ else if (__u <= __c2)
+ {
+ const double __n = _M_nd(__urng);
+ const double __y = 1 + std::abs(__n) * __param._M_scx;
+ __x = std::ceil(__y);
+ __w = __y * (2 - __y) * __param._M_1cx;
+ if (__x > __param._M_d)
+ continue;
+ }
+ else if (__u <= __c3)
+ // NB: This case not in the book, nor in the Errata,
+ // but should be ok...
+ __x = -1;
+ else if (__u <= __c4)
+ __x = 0;
+ else if (__u <= __c5)
+ __x = 1;
+ else
+ {
+ const double __v = -std::log(__aurng());
+ const double __y = __param._M_d
+ + __v * __2cx / __param._M_d;
+ __x = std::ceil(__y);
+ __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
+ }
+
+ __reject = (__w - __e - __x * __param._M_lm_thr
+ > __param._M_lfm - std::lgamma(__x + __m + 1));
+
+ __reject |= __x + __m >= __thr;
+
+ } while (__reject);
+
+ return result_type(__x + __m + __naf);
+ }
+ else
+#endif
+ {
+ _IntType __x = 0;
+ double __prod = 1.0;
+
+ do
+ {
+ __prod *= __aurng();
+ __x += 1;
+ }
+ while (__prod > __param._M_lm_thr);
+
+ return __x - 1;
+ }
+ }
+
+ template<typename _IntType,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const poisson_distribution<_IntType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<double>::digits10 + 1);
+
+ __os << __x.mean() << __space << __x._M_nd;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _IntType,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ poisson_distribution<_IntType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::skipws);
+
+ double __mean;
+ __is >> __mean >> __x._M_nd;
+ __x.param(typename poisson_distribution<_IntType>::param_type(__mean));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _IntType>
+ void
+ binomial_distribution<_IntType>::param_type::
+ _M_initialize()
+ {
+ const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
+
+ _M_easy = true;
+
+#if _GLIBCXX_USE_C99_MATH_TR1
+ if (_M_t * __p12 >= 8)
+ {
+ _M_easy = false;
+ const double __np = std::floor(_M_t * __p12);
+ const double __pa = __np / _M_t;
+ const double __1p = 1 - __pa;
+
+ const double __pi_4 = 0.7853981633974483096156608458198757L;
+ const double __d1x =
+ std::sqrt(__np * __1p * std::log(32 * __np
+ / (81 * __pi_4 * __1p)));
+ _M_d1 = std::round(std::max(1.0, __d1x));
+ const double __d2x =
+ std::sqrt(__np * __1p * std::log(32 * _M_t * __1p
+ / (__pi_4 * __pa)));
+ _M_d2 = std::round(std::max(1.0, __d2x));
+
+ // sqrt(pi / 2)
+ const double __spi_2 = 1.2533141373155002512078826424055226L;
+ _M_s1 = std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
+ _M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
+ _M_c = 2 * _M_d1 / __np;
+ _M_a1 = std::exp(_M_c) * _M_s1 * __spi_2;
+ const double __a12 = _M_a1 + _M_s2 * __spi_2;
+ const double __s1s = _M_s1 * _M_s1;
+ _M_a123 = __a12 + (std::exp(_M_d1 / (_M_t * __1p))
+ * 2 * __s1s / _M_d1
+ * std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
+ const double __s2s = _M_s2 * _M_s2;
+ _M_s = (_M_a123 + 2 * __s2s / _M_d2
+ * std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
+ _M_lf = (std::lgamma(__np + 1)
+ + std::lgamma(_M_t - __np + 1));
+ _M_lp1p = std::log(__pa / __1p);
+
+ _M_q = -std::log(1 - (__p12 - __pa) / __1p);
+ }
+ else
+#endif
+ _M_q = -std::log(1 - __p12);
+ }
+
+ template<typename _IntType>
+ template<typename _UniformRandomNumberGenerator>
+ typename binomial_distribution<_IntType>::result_type
+ binomial_distribution<_IntType>::
+ _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t)
+ {
+ _IntType __x = 0;
+ double __sum = 0.0;
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
+ __aurng(__urng);
+
+ do
+ {
+ const double __e = -std::log(__aurng());
+ __sum += __e / (__t - __x);
+ __x += 1;
+ }
+ while (__sum <= _M_param._M_q);
+
+ return __x - 1;
+ }
+
+ /**
+ * A rejection algorithm when t * p >= 8 and a simple waiting time
+ * method - the second in the referenced book - otherwise.
+ * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1
+ * is defined.
+ *
+ * Reference:
+ * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag,
+ * New York, 1986, Ch. X, Sect. 4 (+ Errata!).
+ */
+ template<typename _IntType>
+ template<typename _UniformRandomNumberGenerator>
+ typename binomial_distribution<_IntType>::result_type
+ binomial_distribution<_IntType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ result_type __ret;
+ const _IntType __t = __param.t();
+ const _IntType __p = __param.p();
+ const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
+ __aurng(__urng);
+
+#if _GLIBCXX_USE_C99_MATH_TR1
+ if (!__param._M_easy)
+ {
+ double __x;
+
+ // See comments above...
+ const double __naf =
+ (1 - std::numeric_limits<double>::epsilon()) / 2;
+ const double __thr =
+ std::numeric_limits<_IntType>::max() + __naf;
+
+ const double __np = std::floor(__t * __p12);
+
+ // sqrt(pi / 2)
+ const double __spi_2 = 1.2533141373155002512078826424055226L;
+ const double __a1 = __param._M_a1;
+ const double __a12 = __a1 + __param._M_s2 * __spi_2;
+ const double __a123 = __param._M_a123;
+ const double __s1s = __param._M_s1 * __param._M_s1;
+ const double __s2s = __param._M_s2 * __param._M_s2;
+
+ bool __reject;
+ do
+ {
+ const double __u = __param._M_s * __aurng();
+
+ double __v;
+
+ if (__u <= __a1)
+ {
+ const double __n = _M_nd(__urng);
+ const double __y = __param._M_s1 * std::abs(__n);
+ __reject = __y >= __param._M_d1;
+ if (!__reject)
+ {
+ const double __e = -std::log(__aurng());
+ __x = std::floor(__y);
+ __v = -__e - __n * __n / 2 + __param._M_c;
+ }
+ }
+ else if (__u <= __a12)
+ {
+ const double __n = _M_nd(__urng);
+ const double __y = __param._M_s2 * std::abs(__n);
+ __reject = __y >= __param._M_d2;
+ if (!__reject)
+ {
+ const double __e = -std::log(__aurng());
+ __x = std::floor(-__y);
+ __v = -__e - __n * __n / 2;
+ }
+ }
+ else if (__u <= __a123)
+ {
+ const double __e1 = -std::log(__aurng());
+ const double __e2 = -std::log(__aurng());
+
+ const double __y = __param._M_d1
+ + 2 * __s1s * __e1 / __param._M_d1;
+ __x = std::floor(__y);
+ __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
+ -__y / (2 * __s1s)));
+ __reject = false;
+ }
+ else
+ {
+ const double __e1 = -std::log(__aurng());
+ const double __e2 = -std::log(__aurng());
+
+ const double __y = __param._M_d2
+ + 2 * __s2s * __e1 / __param._M_d2;
+ __x = std::floor(-__y);
+ __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
+ __reject = false;
+ }
+
+ __reject = __reject || __x < -__np || __x > __t - __np;
+ if (!__reject)
+ {
+ const double __lfx =
+ std::lgamma(__np + __x + 1)
+ + std::lgamma(__t - (__np + __x) + 1);
+ __reject = __v > __param._M_lf - __lfx
+ + __x * __param._M_lp1p;
+ }
+
+ __reject |= __x + __np >= __thr;
+ }
+ while (__reject);
+
+ __x += __np + __naf;
+
+ const _IntType __z = _M_waiting(__urng, __t - _IntType(__x));
+ __ret = _IntType(__x) + __z;
+ }
+ else
+#endif
+ __ret = _M_waiting(__urng, __t);
+
+ if (__p12 != __p)
+ __ret = __t - __ret;
+ return __ret;
+ }
+
+ template<typename _IntType,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const binomial_distribution<_IntType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<double>::digits10 + 1);
+
+ __os << __x.t() << __space << __x.p()
+ << __space << __x._M_nd;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _IntType,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ binomial_distribution<_IntType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ _IntType __t;
+ double __p;
+ __is >> __t >> __p >> __x._M_nd;
+ __x.param(typename binomial_distribution<_IntType>::
+ param_type(__t, __p));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const exponential_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__os.widen(' '));
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ __os << __x.lambda();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ exponential_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ _RealType __lambda;
+ __is >> __lambda;
+ __x.param(typename exponential_distribution<_RealType>::
+ param_type(__lambda));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType>
+ bool
+ operator==(const normal_distribution<_RealType>& __d1,
+ const normal_distribution<_RealType>& __d2)
+ {
+ if (__d1._M_param == __d2._M_param)
+ {
+ if (__d1._M_saved_available == __d2._M_saved_available)
+ {
+ if (__d1._M_saved_available
+ && __d1._M_saved == __d2._M_saved)
+ return true;
+ else if(!__d1._M_saved_available)
+ return true;
+ else
+ return false;
+ }
+ else
+ return false;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Polar method due to Marsaglia.
+ *
+ * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag,
+ * New York, 1986, Ch. V, Sect. 4.4.
+ */
+ template<typename _RealType>
+ template<typename _UniformRandomNumberGenerator>
+ typename normal_distribution<_RealType>::result_type
+ normal_distribution<_RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ result_type __ret;
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+
+ if (_M_saved_available)
+ {
+ _M_saved_available = false;
+ __ret = _M_saved;
+ }
+ else
+ {
+ result_type __x, __y, __r2;
+ do
+ {
+ __x = result_type(2.0) * __aurng() - 1.0;
+ __y = result_type(2.0) * __aurng() - 1.0;
+ __r2 = __x * __x + __y * __y;
+ }
+ while (__r2 > 1.0 || __r2 == 0.0);
+
+ const result_type __mult = std::sqrt(-2 * std::log(__r2) / __r2);
+ _M_saved = __x * __mult;
+ _M_saved_available = true;
+ __ret = __y * __mult;
+ }
+
+ __ret = __ret * __param.stddev() + __param.mean();
+ return __ret;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const normal_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ __os << __x.mean() << __space << __x.stddev()
+ << __space << __x._M_saved_available;
+ if (__x._M_saved_available)
+ __os << __space << __x._M_saved;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ normal_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ double __mean, __stddev;
+ __is >> __mean >> __stddev
+ >> __x._M_saved_available;
+ if (__x._M_saved_available)
+ __is >> __x._M_saved;
+ __x.param(typename normal_distribution<_RealType>::
+ param_type(__mean, __stddev));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType>
+ template<typename _UniformRandomNumberGenerator>
+ typename lognormal_distribution<_RealType>::result_type
+ lognormal_distribution<_RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ _RealType __u, __v, __r2, __normal;
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+
+ do
+ {
+ // Choose x,y in uniform square (-1,-1) to (+1,+1).
+ __u = 2 * __aurng() - 1;
+ __v = 2 * __aurng() - 1;
+
+ // See if it is in the unit circle.
+ __r2 = __u * __u + __v * __v;
+ }
+ while (__r2 > 1 || __r2 == 0);
+
+ __normal = __u * std::sqrt(-2 * std::log(__r2) / __r2);
+
+ return std::exp(__p.s() * __normal + __p.m());
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const lognormal_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ __os << __x.m() << __space << __x.s();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ lognormal_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ _RealType __m, __s;
+ __is >> __m >> __s;
+ __x.param(typename lognormal_distribution<_RealType>::
+ param_type(__m, __s));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType>
+ template<typename _UniformRandomNumberGenerator>
+ typename chi_squared_distribution<_RealType>::result_type
+ chi_squared_distribution<_RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ typename gamma_distribution<_RealType>::param_type
+ __gamma_param(__p.n() / 2, 1.0);
+ gamma_distribution<_RealType> __gamma(__gamma_param);
+ return 2 * __gamma(__urng);
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const chi_squared_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ __os << __x.n();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ chi_squared_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ _RealType __n;
+ __is >> __n;
+ __x.param(typename chi_squared_distribution<_RealType>::
+ param_type(__n));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType>
+ template<typename _UniformRandomNumberGenerator>
+ typename cauchy_distribution<_RealType>::result_type
+ cauchy_distribution<_RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+ _RealType __u;
+ do
+ {
+ __u = __aurng();
+ }
+ while (__u == 0.5);
+
+ return __p.a() + __p.b() * std::tan(M_PI * __u);
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const cauchy_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ __os << __x.a() << __space << __x.b();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ cauchy_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ _RealType __a, __b;
+ __is >> __a >> __b;
+ __x.param(typename cauchy_distribution<_RealType>::
+ param_type(__a, __b));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType>
+ template<typename _UniformRandomNumberGenerator>
+ typename fisher_f_distribution<_RealType>::result_type
+ fisher_f_distribution<_RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ gamma_distribution<_RealType> __gamma;
+ _RealType __ym = __gamma(__urng,
+ typename gamma_distribution<_RealType>::param_type(__p.m() / 2, 2));
+
+ _RealType __yn = __gamma(__urng,
+ typename gamma_distribution<_RealType>::param_type(__p.n() / 2, 2));
+
+ return (__ym * __p.n()) / (__yn * __p.m());
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const fisher_f_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ __os << __x.m() << __space << __x.n();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ fisher_f_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ _RealType __m, __n;
+ __is >> __m >> __n;
+ __x.param(typename fisher_f_distribution<_RealType>::
+ param_type(__m, __n));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ //
+ // This could be operator() for a Gaussian distribution.
+ //
+ template<typename _RealType>
+ template<typename _UniformRandomNumberGenerator>
+ typename student_t_distribution<_RealType>::result_type
+ student_t_distribution<_RealType>::
+ _M_gaussian(_UniformRandomNumberGenerator& __urng,
+ const result_type __sigma)
+ {
+ _RealType __x, __y, __r2;
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+
+ do
+ {
+ // Choose x,y in uniform square (-1,-1) to (+1,+1).
+ __x = 2 * __aurng() - 1;
+ __y = 2 * __aurng() - 1;
+
+ // See if it is in the unit circle.
+ __r2 = __x * __x + __y * __y;
+ }
+ while (__r2 > 1 || __r2 == 0);
+
+ // Box-Muller transform.
+ return __sigma * __y * std::sqrt(-2 * std::log(__r2) / __r2);
+ }
+
+ template<typename _RealType>
+ template<typename _UniformRandomNumberGenerator>
+ typename student_t_distribution<_RealType>::result_type
+ student_t_distribution<_RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ if (__param.n() <= 2.0)
+ {
+ _RealType __y1 = _M_gaussian(__urng, 1.0);
+ typename chi_squared_distribution<_RealType>::param_type
+ __chisq_param(__param.n());
+ chi_squared_distribution<_RealType> __chisq(__chisq_param);
+ _RealType __y2 = __chisq(__urng);
+
+ return __y1 / std::sqrt(__y2 / __param.n());
+ }
+ else
+ {
+ _RealType __y1, __y2, __z;
+ do
+ {
+ __y1 = _M_gaussian(__urng, 1.0);
+ typename exponential_distribution<_RealType>::param_type
+ __exp_param(1.0 / (__param.n() / 2.0 - 1.0));
+ exponential_distribution<_RealType>
+ __exponential(__exp_param);
+ __y2 = __exponential(__urng);
+
+ __z = __y1 * __y1 / (__param.n() - 2.0);
+ }
+ while (1.0 - __z < 0.0 || std::exp(-__y2 - __z) > (1.0 - __z));
+
+ // Note that there is a typo in Knuth's formula, the line below
+ // is taken from the original paper of Marsaglia, Mathematics of
+ // Computation, 34 (1980), p 234-256
+ return __y1 / std::sqrt((1.0 - 2.0 / __param.n()) * (1.0 - __z));
+ }
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const student_t_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ __os << __x.n();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ student_t_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ _RealType __n;
+ __is >> __n;
+ __x.param(typename student_t_distribution<_RealType>::param_type(__n));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType>
+ void
+ gamma_distribution<_RealType>::param_type::
+ _M_initialize()
+ {
+ if (_M_alpha >= 1)
+ _M_l_d = std::sqrt(2 * _M_alpha - 1);
+ else
+ _M_l_d = (std::pow(_M_alpha, _M_alpha / (1 - _M_alpha))
+ * (1 - _M_alpha));
+ }
+
+ /**
+ * Cheng's rejection algorithm GB for alpha >= 1 and a modification
+ * of Vaduva's rejection from Weibull algorithm due to Devroye for
+ * alpha < 1.
+ *
+ * References:
+ * Cheng, R. C. "The Generation of Gamma Random Variables with Non-integral
+ * Shape Parameter." Applied Statistics, 26, 71-75, 1977.
+ *
+ * Vaduva, I. "Computer Generation of Gamma Gandom Variables by Rejection
+ * and Composition Procedures." Math. Operationsforschung and Statistik,
+ * Series in Statistics, 8, 545-576, 1977.
+ *
+ * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag,
+ * New York, 1986, Ch. IX, Sect. 3.4 (+ Errata!).
+ */
+ template<typename _RealType>
+ template<typename _UniformRandomNumberGenerator>
+ typename gamma_distribution<_RealType>::result_type
+ gamma_distribution<_RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ result_type __x;
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+
+ bool __reject;
+ const _RealType __alpha = __param.alpha();
+ const _RealType __beta = __param.beta();
+ if (__alpha >= 1)
+ {
+ // alpha - log(4)
+ const result_type __b = __alpha
+ - result_type(1.3862943611198906188344642429163531L);
+ const result_type __c = __alpha + __param._M_l_d;
+ const result_type __1l = 1 / __param._M_l_d;
+
+ // 1 + log(9 / 2)
+ const result_type __k = 2.5040773967762740733732583523868748L;
+
+ do
+ {
+ const result_type __u = __aurng() / __beta;
+ const result_type __v = __aurng() / __beta;
+
+ const result_type __y = __1l * std::log(__v / (1 - __v));
+ __x = __alpha * std::exp(__y);
+
+ const result_type __z = __u * __v * __v;
+ const result_type __r = __b + __c * __y - __x;
+
+ __reject = __r < result_type(4.5) * __z - __k;
+ if (__reject)
+ __reject = __r < std::log(__z);
+ }
+ while (__reject);
+ }
+ else
+ {
+ const result_type __c = 1 / __alpha;
+
+ do
+ {
+ const result_type __z = -std::log(__aurng() / __beta);
+ const result_type __e = -std::log(__aurng() / __beta);
+
+ __x = std::pow(__z, __c);
+
+ __reject = __z + __e < __param._M_l_d + __x;
+ }
+ while (__reject);
+ }
+
+ return __beta * __x;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const gamma_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ __os << __x.alpha() << __space << __x.beta();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ gamma_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ _RealType __alpha, __beta;
+ __is >> __alpha >> __beta;
+ __x.param(typename gamma_distribution<_RealType>::
+ param_type(__alpha, __beta));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const weibull_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ __os << __x.a() << __space << __x.b();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ weibull_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ _RealType __a, __b;
+ __is >> __a >> __b;
+ __x.param(typename weibull_distribution<_RealType>::
+ param_type(__a, __b));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType>
+ template<typename _UniformRandomNumberGenerator>
+ typename extreme_value_distribution<_RealType>::result_type
+ extreme_value_distribution<_RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+ return __p.a() - __p.b() * std::log(-std::log(__aurng()));
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const extreme_value_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ __os << __x.a() << __space << __x.b();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ extreme_value_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ _RealType __a, __b;
+ __is >> __a >> __b;
+ __x.param(typename extreme_value_distribution<_RealType>::
+ param_type(__a, __b));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _IntType>
+ void
+ discrete_distribution<_IntType>::param_type::
+ _M_initialize()
+ {
+ if (_M_prob.size() < 2)
+ {
+ _M_prob.clear();
+ _M_prob.push_back(1.0);
+ return;
+ }
+
+ double __sum = std::accumulate(_M_prob.begin(), _M_prob.end(), 0.0);
+ // Now normalize the densities.
+ std::transform(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
+ std::bind2nd(std::divides<double>(), __sum));
+ // Accumulate partial sums.
+ std::partial_sum(_M_prob.begin(), _M_prob.end(),
+ std::back_inserter(_M_cp));
+ // Make sure the last cumulative probablility is one.
+ _M_cp[_M_cp.size() - 1] = 1.0;
+ }
+
+ template<typename _IntType>
+ template<typename _Func>
+ discrete_distribution<_IntType>::param_type::
+ param_type(size_t __nw, double __xmin, double __xmax,
+ _Func __fw)
+ : _M_prob(), _M_cp()
+ {
+ for (size_t __i = 0; __i < __nw; ++__i)
+ {
+ const double __x = ((__nw - __i - 0.5) * __xmin
+ + (__i + 0.5) * __xmax) / __nw;
+ _M_prob.push_back(__fw(__x));
+ }
+
+ _M_initialize();
+ }
+
+ template<typename _IntType>
+ template<typename _UniformRandomNumberGenerator>
+ typename discrete_distribution<_IntType>::result_type
+ discrete_distribution<_IntType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+
+ const double __p = __aurng();
+ auto __pos = std::lower_bound(__param._M_cp.begin(),
+ __param._M_cp.end(), __p);
+ if (__pos == __param._M_cp.end())
+ return 0;
+ const size_t __i = __pos - __param._M_cp.begin();
+
+ return __i;
+ }
+
+ template<typename _IntType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const discrete_distribution<_IntType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<double>::digits10 + 1);
+
+ std::vector<double> __prob = __x.probabilities();
+ __os << __prob.size();
+ for (auto __dit = __prob.begin(); __dit != __prob.end(); ++__dit)
+ __os << __space << *__dit;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _IntType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ discrete_distribution<_IntType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ size_t __n;
+ __is >> __n;
+
+ std::vector<double> __prob_vec;
+ for (; __n != 0; --__n)
+ {
+ double __prob;
+ __is >> __prob;
+ __prob_vec.push_back(__prob);
+ }
+
+ __x.param(typename discrete_distribution<_IntType>::
+ param_type(__prob_vec.begin(), __prob_vec.end()));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType>
+ void
+ piecewise_constant_distribution<_RealType>::param_type::
+ _M_initialize()
+ {
+ if (_M_int.size() < 2)
+ {
+ _M_int.clear();
+ _M_int.push_back(_RealType(0));
+ _M_int.push_back(_RealType(1));
+
+ _M_den.clear();
+ _M_den.push_back(1.0);
+
+ return;
+ }
+
+ double __sum = 0.0;
+ for (size_t __i = 0; __i < _M_den.size(); ++__i)
+ {
+ __sum += _M_den[__i] * (_M_int[__i + 1] - _M_int[__i]);
+ _M_cp.push_back(__sum);
+ }
+
+ // Now normalize the densities...
+ std::transform(_M_den.begin(), _M_den.end(), _M_den.begin(),
+ std::bind2nd(std::divides<double>(), __sum));
+ // ... and partial sums.
+ std::transform(_M_cp.begin(), _M_cp.end(), _M_cp.begin(),
+ std::bind2nd(std::divides<double>(), __sum));
+ // Make sure the last cumulative probablility is one.
+ _M_cp[_M_cp.size() - 1] = 1.0;
+ }
+
+ template<typename _RealType>
+ piecewise_constant_distribution<_RealType>::param_type::
+ param_type()
+ : _M_int(), _M_den(), _M_cp()
+ {
+ _M_initialize();
+ }
+
+ template<typename _RealType>
+ template<typename _InputIteratorB, typename _InputIteratorW>
+ piecewise_constant_distribution<_RealType>::param_type::
+ param_type(_InputIteratorB __bbegin,
+ _InputIteratorB __bend,
+ _InputIteratorW __wbegin)
+ : _M_int(), _M_den(), _M_cp()
+ {
+ do
+ {
+ _M_int.push_back(*__bbegin);
+ ++__bbegin;
+ if (__bbegin != __bend)
+ {
+ _M_den.push_back(*__wbegin);
+ ++__wbegin;
+ }
+ }
+ while (__bbegin != __bend);
+
+ _M_initialize();
+ }
+
+ template<typename _RealType>
+ template<typename _Func>
+ piecewise_constant_distribution<_RealType>::param_type::
+ param_type(initializer_list<_RealType> __bil, _Func __fw)
+ : _M_int(), _M_den(), _M_cp()
+ {
+ for (auto __biter = __bil.begin(); __biter != __bil.end(); ++__biter)
+ _M_int.push_back(*__biter);
+
+ for (size_t __i = 0; __i < _M_int.size() - 1; ++__i)
+ {
+ _RealType __x = 0.5 * (_M_int[__i] + _M_int[__i + 1]);
+ _M_den.push_back(__fw(__x));
+ }
+
+ _M_initialize();
+ }
+
+ template<typename _RealType>
+ template<typename _Func>
+ piecewise_constant_distribution<_RealType>::param_type::
+ param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
+ _Func __fw)
+ : _M_int(), _M_den(), _M_cp()
+ {
+ for (size_t __i = 0; __i <= __nw; ++__i)
+ {
+ const _RealType __x = ((__nw - __i) * __xmin
+ + __i * __xmax) / __nw;
+ _M_int.push_back(__x);
+ }
+ for (size_t __i = 0; __i < __nw; ++__i)
+ {
+ const _RealType __x = ((__nw - __i - 0.5) * __xmin
+ + (__i + 0.5) * __xmax) / __nw;
+ _M_den.push_back(__fw(__x));
+ }
+
+ _M_initialize();
+ }
+
+ template<typename _RealType>
+ template<typename _UniformRandomNumberGenerator>
+ typename piecewise_constant_distribution<_RealType>::result_type
+ piecewise_constant_distribution<_RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+
+ const double __p = __aurng();
+ auto __pos = std::lower_bound(__param._M_cp.begin(),
+ __param._M_cp.end(), __p);
+ const size_t __i = __pos - __param._M_cp.begin();
+
+ return __param._M_int[__i]
+ + (__p - __param._M_cp[__i]) / __param._M_den[__i];
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const piecewise_constant_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ std::vector<_RealType> __int = __x.intervals();
+ __os << __int.size() - 1;
+
+ for (auto __xit = __int.begin(); __xit != __int.end(); ++__xit)
+ __os << __space << *__xit;
+
+ std::vector<double> __den = __x.densities();
+ for (auto __dit = __den.begin(); __dit != __den.end(); ++__dit)
+ __os << __space << *__dit;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ piecewise_constant_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ size_t __n;
+ __is >> __n;
+
+ std::vector<_RealType> __int_vec;
+ for (size_t __i = 0; __i <= __n; ++__i)
+ {
+ _RealType __int;
+ __is >> __int;
+ __int_vec.push_back(__int);
+ }
+
+ std::vector<double> __den_vec;
+ for (size_t __i = 0; __i < __n; ++__i)
+ {
+ double __den;
+ __is >> __den;
+ __den_vec.push_back(__den);
+ }
+
+ __x.param(typename piecewise_constant_distribution<_RealType>::
+ param_type(__int_vec.begin(), __int_vec.end(), __den_vec.begin()));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType>
+ void
+ piecewise_linear_distribution<_RealType>::param_type::
+ _M_initialize()
+ {
+ if (_M_int.size() < 2)
+ {
+ _M_int.clear();
+ _M_int.push_back(_RealType(0));
+ _M_int.push_back(_RealType(1));
+
+ _M_den.clear();
+ _M_den.push_back(1.0);
+ _M_den.push_back(1.0);
+
+ return;
+ }
+
+ double __sum = 0.0;
+ for (size_t __i = 0; __i < _M_int.size() - 1; ++__i)
+ {
+ const _RealType __delta = _M_int[__i + 1] - _M_int[__i];
+ __sum += 0.5 * (_M_den[__i + 1] + _M_den[__i]) * __delta;
+ _M_cp.push_back(__sum);
+ _M_m.push_back((_M_den[__i + 1] - _M_den[__i]) / __delta);
+ }
+
+ // Now normalize the densities...
+ std::transform(_M_den.begin(), _M_den.end(), _M_den.begin(),
+ std::bind2nd(std::divides<double>(),__sum));
+ // ... and partial sums...
+ std::transform(_M_cp.begin(), _M_cp.end(), _M_cp.begin(),
+ std::bind2nd(std::divides<double>(), __sum));
+ // ... and slopes.
+ std::transform(_M_m.begin(), _M_m.end(), _M_m.begin(),
+ std::bind2nd(std::divides<double>(), __sum));
+ // Make sure the last cumulative probablility is one.
+ _M_cp[_M_cp.size() - 1] = 1.0;
+ }
+
+ template<typename _RealType>
+ piecewise_linear_distribution<_RealType>::param_type::
+ param_type()
+ : _M_int(), _M_den(), _M_cp(), _M_m()
+ {
+ _M_initialize();
+ }
+
+ template<typename _RealType>
+ template<typename _InputIteratorB, typename _InputIteratorW>
+ piecewise_linear_distribution<_RealType>::param_type::
+ param_type(_InputIteratorB __bbegin,
+ _InputIteratorB __bend,
+ _InputIteratorW __wbegin)
+ : _M_int(), _M_den(), _M_cp(), _M_m()
+ {
+ for (; __bbegin != __bend; ++__bbegin, ++__wbegin)
+ {
+ _M_int.push_back(*__bbegin);
+ _M_den.push_back(*__wbegin);
+ }
+
+ _M_initialize();
+ }
+
+ template<typename _RealType>
+ template<typename _Func>
+ piecewise_linear_distribution<_RealType>::param_type::
+ param_type(initializer_list<_RealType> __bil, _Func __fw)
+ : _M_int(), _M_den(), _M_cp(), _M_m()
+ {
+ for (auto __biter = __bil.begin(); __biter != __bil.end(); ++__biter)
+ {
+ _M_int.push_back(*__biter);
+ _M_den.push_back(__fw(*__biter));
+ }
+
+ _M_initialize();
+ }
+
+ template<typename _RealType>
+ template<typename _Func>
+ piecewise_linear_distribution<_RealType>::param_type::
+ param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
+ _Func __fw)
+ : _M_int(), _M_den(), _M_cp(), _M_m()
+ {
+ for (size_t __i = 0; __i <= __nw; ++__i)
+ {
+ const _RealType __x = ((__nw - __i) * __xmin
+ + __i * __xmax) / __nw;
+ _M_int.push_back(__x);
+ _M_den.push_back(__fw(__x));
+ }
+
+ _M_initialize();
+ }
+
+ template<typename _RealType>
+ template<typename _UniformRandomNumberGenerator>
+ typename piecewise_linear_distribution<_RealType>::result_type
+ piecewise_linear_distribution<_RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ result_type __x;
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+
+ const double __p = __aurng();
+ auto __pos = std::lower_bound(__param._M_cp.begin(),
+ __param._M_cp.end(), __p);
+ const size_t __i = __pos - __param._M_cp.begin();
+ const double __a = 0.5 * __param._M_m[__i];
+ const double __b = __param._M_den[__i];
+ const double __c = __param._M_cp[__i];
+ const double __q = -0.5 * (__b
+#if _GLIBCXX_USE_C99_MATH_TR1
+ + std::copysign(std::sqrt(__b * __b
+ - 4.0 * __a * __c), __b));
+#else
+ + (__b < 0.0 ? -1.0 : 1.0)
+ * std::sqrt(__b * __b - 4.0 * __a * __c)));
+#endif
+ const double __x0 = __param._M_int[__i];
+ const double __x1 = __q / __a;
+ const double __x2 = __c / __q;
+ __x = std::max(__x0 + __x1, __x0 + __x2);
+
+ return __x;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const piecewise_linear_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(std::numeric_limits<_RealType>::digits10 + 1);
+
+ std::vector<_RealType> __int = __x.intervals();
+ __os << __int.size() - 1;
+
+ for (auto __xit = __int.begin(); __xit != __int.end(); ++__xit)
+ __os << __space << *__xit;
+
+ std::vector<double> __den = __x.densities();
+ for (auto __dit = __den.begin(); __dit != __den.end(); ++__dit)
+ __os << __space << *__dit;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ piecewise_linear_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ size_t __n;
+ __is >> __n;
+
+ std::vector<_RealType> __int_vec;
+ for (size_t __i = 0; __i <= __n; ++__i)
+ {
+ _RealType __int;
+ __is >> __int;
+ __int_vec.push_back(__int);
+ }
+
+ std::vector<double> __den_vec;
+ for (size_t __i = 0; __i <= __n; ++__i)
+ {
+ double __den;
+ __is >> __den;
+ __den_vec.push_back(__den);
+ }
+
+ __x.param(typename piecewise_linear_distribution<_RealType>::
+ param_type(__int_vec.begin(), __int_vec.end(), __den_vec.begin()));
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _IntType>
+ seed_seq::seed_seq(std::initializer_list<_IntType> __il)
+ {
+ for (auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
+ _M_v.push_back(__detail::__mod<result_type, 1, 0,
+ __detail::_Shift<result_type, 32>::__value>(*__iter));
+ }
+
+ template<typename _InputIterator>
+ seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
+ {
+ for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
+ _M_v.push_back(__detail::__mod<result_type, 1, 0,
+ __detail::_Shift<result_type, 32>::__value>(*__iter));
+ }
+
+ template<typename _RandomAccessIterator>
+ void
+ seed_seq::generate(_RandomAccessIterator __begin,
+ _RandomAccessIterator __end)
+ {
+ typedef typename iterator_traits<_RandomAccessIterator>::value_type
+ __Type;
+
+ if (__begin == __end)
+ return;
+
+ std::fill(__begin, __end, __Type(0x8b8b8b8bU));
+
+ const size_t __n = __end - __begin;
+ const size_t __s = _M_v.size();
+ const size_t __t = (__n >= 623) ? 11
+ : (__n >= 68) ? 7
+ : (__n >= 39) ? 5
+ : (__n >= 7) ? 3
+ : (__n - 1) / 2;
+ const size_t __p = (__n - __t) / 2;
+ const size_t __q = __p + __t;
+ const size_t __m = std::max(__s + 1, __n);
+
+ for (size_t __k = 0; __k < __m; ++__k)
+ {
+ __Type __arg = __begin[__k % __n]
+ ^ __begin[(__k + __p) % __n]
+ ^ __begin[(__k - 1) % __n];
+ __Type __r1 = __arg ^ (__arg << 27);
+ __r1 = __detail::__mod<__Type, 1664525U, 0U,
+ __detail::_Shift<__Type, 32>::__value>(__r1);
+ __Type __r2 = __r1;
+ if (__k == 0)
+ __r2 += __s;
+ else if (__k <= __s)
+ __r2 += __k % __n + _M_v[__k - 1];
+ else
+ __r2 += __k % __n;
+ __r2 = __detail::__mod<__Type, 1U, 0U,
+ __detail::_Shift<__Type, 32>::__value>(__r2);
+ __begin[(__k + __p) % __n] += __r1;
+ __begin[(__k + __q) % __n] += __r2;
+ __begin[__k % __n] = __r2;
+ }
+
+ for (size_t __k = __m; __k < __m + __n; ++__k)
+ {
+ __Type __arg = __begin[__k % __n]
+ + __begin[(__k + __p) % __n]
+ + __begin[(__k - 1) % __n];
+ __Type __r3 = __arg ^ (__arg << 27);
+ __r3 = __detail::__mod<__Type, 1566083941U, 0U,
+ __detail::_Shift<__Type, 32>::__value>(__r3);
+ __Type __r4 = __r3 - __k % __n;
+ __r4 = __detail::__mod<__Type, 1U, 0U,
+ __detail::_Shift<__Type, 32>::__value>(__r4);
+ __begin[(__k + __p) % __n] ^= __r4;
+ __begin[(__k + __q) % __n] ^= __r3;
+ __begin[__k % __n] = __r4;
+ }
+ }
+
+ template<typename _RealType, size_t __bits,
+ typename _UniformRandomNumberGenerator>
+ _RealType
+ generate_canonical(_UniformRandomNumberGenerator& __urng)
+ {
+ const size_t __b
+ = std::min(static_cast<size_t>(std::numeric_limits<_RealType>::digits),
+ __bits);
+ const long double __r = static_cast<long double>(__urng.max())
+ - static_cast<long double>(__urng.min()) + 1.0L;
+ const size_t __log2r = std::log2l(__r);
+ size_t __k = std::max<size_t>(1UL, (__b + __log2r - 1UL) / __log2r);
+ _RealType __sum = _RealType(0);
+ _RealType __tmp = _RealType(1);
+ for (; __k != 0; --__k)
+ {
+ __sum += _RealType(__urng() - __urng.min()) * __tmp;
+ __tmp *= __r;
+ }
+ return __sum / __tmp;
+ }
+
+}
diff --git a/libstdc++-v3/include/std/random b/libstdc++-v3/include/std/random
index 395604b246a..52a0b73cf33 100644
--- a/libstdc++-v3/include/std/random
+++ b/libstdc++-v3/include/std/random
@@ -56,18 +56,10 @@
#include <debug/debug.h>
#include <type_traits>
-#if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
-# include <tr1_impl/random>
-#else
-# define _GLIBCXX_INCLUDE_AS_CXX0X
-# define _GLIBCXX_BEGIN_NAMESPACE_TR1
-# define _GLIBCXX_END_NAMESPACE_TR1
-# define _GLIBCXX_TR1
-# include <tr1_impl/random>
-# undef _GLIBCXX_TR1
-# undef _GLIBCXX_END_NAMESPACE_TR1
-# undef _GLIBCXX_BEGIN_NAMESPACE_TR1
-# undef _GLIBCXX_INCLUDE_AS_CXX0X
+#include <bits/random.h>
+
+#ifndef _GLIBCXX_EXPORT_TEMPLATE
+# include <bits/random.tcc>
#endif
#endif // __GXX_EXPERIMENTAL_CXX0X__
diff --git a/libstdc++-v3/include/tr1/random b/libstdc++-v3/include/tr1/random
index 49a3b21cd81..6f6e3234b89 100644
--- a/libstdc++-v3/include/tr1/random
+++ b/libstdc++-v3/include/tr1/random
@@ -55,16 +55,12 @@
#include <tr1/cmath>
#if defined(_GLIBCXX_INCLUDE_AS_TR1)
-# include <tr1_impl/random>
+# include <tr1/random.h>
#else
# define _GLIBCXX_INCLUDE_AS_TR1
-# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 {
-# define _GLIBCXX_END_NAMESPACE_TR1 }
# define _GLIBCXX_TR1 tr1::
-# include <tr1_impl/random>
+# include <tr1/random.h>
# undef _GLIBCXX_TR1
-# undef _GLIBCXX_END_NAMESPACE_TR1
-# undef _GLIBCXX_BEGIN_NAMESPACE_TR1
# undef _GLIBCXX_INCLUDE_AS_TR1
#endif
diff --git a/libstdc++-v3/include/tr1/random.h b/libstdc++-v3/include/tr1/random.h
new file mode 100644
index 00000000000..5a0f6b741b6
--- /dev/null
+++ b/libstdc++-v3/include/tr1/random.h
@@ -0,0 +1,2436 @@
+// random number generation -*- C++ -*-
+
+// Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/**
+ * @file tr1/random.h
+ * This is an internal header file, included by other library headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef _GLIBCXX_TR1_RANDOM_H
+#define _GLIBCXX_TR1_RANDOM_H 1
+
+#pragma GCC system_header
+
+#if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
+# error TR1 header cannot be included from C++0x header
+#endif
+
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <string>
+#include <iosfwd>
+#include <limits>
+#include <ext/type_traits.h>
+#include <ext/numeric_traits.h>
+#include <bits/concept_check.h>
+#include <debug/debug.h>
+#include <tr1/type_traits>
+#include <tr1/cmath>
+
+namespace std
+{
+namespace tr1
+{
+
+ // [5.1] Random number generation
+
+ /**
+ * @addtogroup tr1_random Random Number Generation
+ * A facility for generating random numbers on selected distributions.
+ * @{
+ */
+
+ /*
+ * Implementation-space details.
+ */
+ namespace __detail
+ {
+ template<typename _UIntType, int __w,
+ bool = __w < std::numeric_limits<_UIntType>::digits>
+ struct _Shift
+ { static const _UIntType __value = 0; };
+
+ template<typename _UIntType, int __w>
+ struct _Shift<_UIntType, __w, true>
+ { static const _UIntType __value = _UIntType(1) << __w; };
+
+ template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool>
+ struct _Mod;
+
+ // Dispatch based on modulus value to prevent divide-by-zero compile-time
+ // errors when m == 0.
+ template<typename _Tp, _Tp __a, _Tp __c, _Tp __m>
+ inline _Tp
+ __mod(_Tp __x)
+ { return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); }
+
+ typedef __gnu_cxx::__conditional_type<(sizeof(unsigned) == 4),
+ unsigned, unsigned long>::__type _UInt32Type;
+
+ /*
+ * An adaptor class for converting the output of any Generator into
+ * the input for a specific Distribution.
+ */
+ template<typename _Engine, typename _Distribution>
+ struct _Adaptor
+ {
+ typedef typename remove_reference<_Engine>::type _BEngine;
+ typedef typename _BEngine::result_type _Engine_result_type;
+ typedef typename _Distribution::input_type result_type;
+
+ public:
+ _Adaptor(const _Engine& __g)
+ : _M_g(__g) { }
+
+ result_type
+ min() const
+ {
+ result_type __return_value;
+ if (is_integral<_Engine_result_type>::value
+ && is_integral<result_type>::value)
+ __return_value = _M_g.min();
+ else
+ __return_value = result_type(0);
+ return __return_value;
+ }
+
+ result_type
+ max() const
+ {
+ result_type __return_value;
+ if (is_integral<_Engine_result_type>::value
+ && is_integral<result_type>::value)
+ __return_value = _M_g.max();
+ else if (!is_integral<result_type>::value)
+ __return_value = result_type(1);
+ else
+ __return_value = std::numeric_limits<result_type>::max() - 1;
+ return __return_value;
+ }
+
+ /*
+ * Converts a value generated by the adapted random number generator
+ * into a value in the input domain for the dependent random number
+ * distribution.
+ *
+ * Because the type traits are compile time constants only the
+ * appropriate clause of the if statements will actually be emitted
+ * by the compiler.
+ */
+ result_type
+ operator()()
+ {
+ result_type __return_value;
+ if (is_integral<_Engine_result_type>::value
+ && is_integral<result_type>::value)
+ __return_value = _M_g();
+ else if (!is_integral<_Engine_result_type>::value
+ && !is_integral<result_type>::value)
+ __return_value = result_type(_M_g() - _M_g.min())
+ / result_type(_M_g.max() - _M_g.min());
+ else if (is_integral<_Engine_result_type>::value
+ && !is_integral<result_type>::value)
+ __return_value = result_type(_M_g() - _M_g.min())
+ / result_type(_M_g.max() - _M_g.min() + result_type(1));
+ else
+ __return_value = (((_M_g() - _M_g.min())
+ / (_M_g.max() - _M_g.min()))
+ * std::numeric_limits<result_type>::max());
+ return __return_value;
+ }
+
+ private:
+ _Engine _M_g;
+ };
+
+ // Specialization for _Engine*.
+ template<typename _Engine, typename _Distribution>
+ struct _Adaptor<_Engine*, _Distribution>
+ {
+ typedef typename _Engine::result_type _Engine_result_type;
+ typedef typename _Distribution::input_type result_type;
+
+ public:
+ _Adaptor(_Engine* __g)
+ : _M_g(__g) { }
+
+ result_type
+ min() const
+ {
+ result_type __return_value;
+ if (is_integral<_Engine_result_type>::value
+ && is_integral<result_type>::value)
+ __return_value = _M_g->min();
+ else
+ __return_value = result_type(0);
+ return __return_value;
+ }
+
+ result_type
+ max() const
+ {
+ result_type __return_value;
+ if (is_integral<_Engine_result_type>::value
+ && is_integral<result_type>::value)
+ __return_value = _M_g->max();
+ else if (!is_integral<result_type>::value)
+ __return_value = result_type(1);
+ else
+ __return_value = std::numeric_limits<result_type>::max() - 1;
+ return __return_value;
+ }
+
+ result_type
+ operator()()
+ {
+ result_type __return_value;
+ if (is_integral<_Engine_result_type>::value
+ && is_integral<result_type>::value)
+ __return_value = (*_M_g)();
+ else if (!is_integral<_Engine_result_type>::value
+ && !is_integral<result_type>::value)
+ __return_value = result_type((*_M_g)() - _M_g->min())
+ / result_type(_M_g->max() - _M_g->min());
+ else if (is_integral<_Engine_result_type>::value
+ && !is_integral<result_type>::value)
+ __return_value = result_type((*_M_g)() - _M_g->min())
+ / result_type(_M_g->max() - _M_g->min() + result_type(1));
+ else
+ __return_value = ((((*_M_g)() - _M_g->min())
+ / (_M_g->max() - _M_g->min()))
+ * std::numeric_limits<result_type>::max());
+ return __return_value;
+ }
+
+ private:
+ _Engine* _M_g;
+ };
+ } // namespace __detail
+
+ /**
+ * Produces random numbers on a given distribution function using a
+ * non-uniform random number generation engine.
+ *
+ * @todo the engine_value_type needs to be studied more carefully.
+ */
+ template<typename _Engine, typename _Dist>
+ class variate_generator
+ {
+ // Concept requirements.
+ __glibcxx_class_requires(_Engine, _CopyConstructibleConcept)
+ // __glibcxx_class_requires(_Engine, _EngineConcept)
+ // __glibcxx_class_requires(_Dist, _EngineConcept)
+
+ public:
+ typedef _Engine engine_type;
+ typedef __detail::_Adaptor<_Engine, _Dist> engine_value_type;
+ typedef _Dist distribution_type;
+ typedef typename _Dist::result_type result_type;
+
+ // tr1:5.1.1 table 5.1 requirement
+ typedef typename __gnu_cxx::__enable_if<
+ is_arithmetic<result_type>::value, result_type>::__type _IsValidType;
+
+ /**
+ * Constructs a variate generator with the uniform random number
+ * generator @p __eng for the random distribution @p __dist.
+ *
+ * @throws Any exceptions which may thrown by the copy constructors of
+ * the @p _Engine or @p _Dist objects.
+ */
+ variate_generator(engine_type __eng, distribution_type __dist)
+ : _M_engine(__eng), _M_dist(__dist) { }
+
+ /**
+ * Gets the next generated value on the distribution.
+ */
+ result_type
+ operator()()
+ { return _M_dist(_M_engine); }
+
+ /**
+ * WTF?
+ */
+ template<typename _Tp>
+ result_type
+ operator()(_Tp __value)
+ { return _M_dist(_M_engine, __value); }
+
+ /**
+ * Gets a reference to the underlying uniform random number generator
+ * object.
+ */
+ engine_value_type&
+ engine()
+ { return _M_engine; }
+
+ /**
+ * Gets a const reference to the underlying uniform random number
+ * generator object.
+ */
+ const engine_value_type&
+ engine() const
+ { return _M_engine; }
+
+ /**
+ * Gets a reference to the underlying random distribution.
+ */
+ distribution_type&
+ distribution()
+ { return _M_dist; }
+
+ /**
+ * Gets a const reference to the underlying random distribution.
+ */
+ const distribution_type&
+ distribution() const
+ { return _M_dist; }
+
+ /**
+ * Gets the closed lower bound of the distribution interval.
+ */
+ result_type
+ min() const
+ { return this->distribution().min(); }
+
+ /**
+ * Gets the closed upper bound of the distribution interval.
+ */
+ result_type
+ max() const
+ { return this->distribution().max(); }
+
+ private:
+ engine_value_type _M_engine;
+ distribution_type _M_dist;
+ };
+
+
+ /**
+ * @addtogroup tr1_random_generators Random Number Generators
+ * @ingroup tr1_random
+ *
+ * These classes define objects which provide random or pseudorandom
+ * numbers, either from a discrete or a continuous interval. The
+ * random number generator supplied as a part of this library are
+ * all uniform random number generators which provide a sequence of
+ * random number uniformly distributed over their range.
+ *
+ * A number generator is a function object with an operator() that
+ * takes zero arguments and returns a number.
+ *
+ * A compliant random number generator must satisfy the following
+ * requirements. <table border=1 cellpadding=10 cellspacing=0>
+ * <caption align=top>Random Number Generator Requirements</caption>
+ * <tr><td>To be documented.</td></tr> </table>
+ *
+ * @{
+ */
+
+ /**
+ * @brief A model of a linear congruential random number generator.
+ *
+ * A random number generator that produces pseudorandom numbers using the
+ * linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$.
+ *
+ * The template parameter @p _UIntType must be an unsigned integral type
+ * large enough to store values up to (__m-1). If the template parameter
+ * @p __m is 0, the modulus @p __m used is
+ * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
+ * parameters @p __a and @p __c must be less than @p __m.
+ *
+ * The size of the state is @f$ 1 @f$.
+ */
+ template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+ class linear_congruential
+ {
+ __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
+ // __glibcpp_class_requires(__a < __m && __c < __m)
+
+ public:
+ /** The type of the generated random value. */
+ typedef _UIntType result_type;
+
+ /** The multiplier. */
+ static const _UIntType multiplier = __a;
+ /** An increment. */
+ static const _UIntType increment = __c;
+ /** The modulus. */
+ static const _UIntType modulus = __m;
+
+ /**
+ * Constructs a %linear_congruential random number generator engine with
+ * seed @p __s. The default seed value is 1.
+ *
+ * @param __s The initial seed value.
+ */
+ explicit
+ linear_congruential(unsigned long __x0 = 1)
+ { this->seed(__x0); }
+
+ /**
+ * Constructs a %linear_congruential random number generator engine
+ * seeded from the generator function @p __g.
+ *
+ * @param __g The seed generator function.
+ */
+ template<class _Gen>
+ linear_congruential(_Gen& __g)
+ { this->seed(__g); }
+
+ /**
+ * Reseeds the %linear_congruential random number generator engine
+ * sequence to the seed @g __s.
+ *
+ * @param __s The new seed.
+ */
+ void
+ seed(unsigned long __s = 1);
+
+ /**
+ * Reseeds the %linear_congruential random number generator engine
+ * sequence using values from the generator function @p __g.
+ *
+ * @param __g the seed generator function.
+ */
+ template<class _Gen>
+ void
+ seed(_Gen& __g)
+ { seed(__g, typename is_fundamental<_Gen>::type()); }
+
+ /**
+ * Gets the smallest possible value in the output range.
+ *
+ * The minimum depends on the @p __c parameter: if it is zero, the
+ * minimum generated must be > 0, otherwise 0 is allowed.
+ */
+ result_type
+ min() const
+ { return (__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) ? 1 : 0; }
+
+ /**
+ * Gets the largest possible value in the output range.
+ */
+ result_type
+ max() const
+ { return __m - 1; }
+
+ /**
+ * Gets the next random number in the sequence.
+ */
+ result_type
+ operator()();
+
+ /**
+ * Compares two linear congruential random number generator
+ * objects of the same type for equality.
+ *
+ * @param __lhs A linear congruential random number generator object.
+ * @param __rhs Another linear congruential random number generator obj.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const linear_congruential& __lhs,
+ const linear_congruential& __rhs)
+ { return __lhs._M_x == __rhs._M_x; }
+
+ /**
+ * Compares two linear congruential random number generator
+ * objects of the same type for inequality.
+ *
+ * @param __lhs A linear congruential random number generator object.
+ * @param __rhs Another linear congruential random number generator obj.
+ *
+ * @returns true if the two objects are not equal, false otherwise.
+ */
+ friend bool
+ operator!=(const linear_congruential& __lhs,
+ const linear_congruential& __rhs)
+ { return !(__lhs == __rhs); }
+
+ /**
+ * Writes the textual representation of the state x(i) of x to @p __os.
+ *
+ * @param __os The output stream.
+ * @param __lcr A % linear_congruential random number generator.
+ * @returns __os.
+ */
+ template<class _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
+ _UIntType1 __m1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const linear_congruential<_UIntType1, __a1, __c1,
+ __m1>& __lcr);
+
+ /**
+ * Sets the state of the engine by reading its textual
+ * representation from @p __is.
+ *
+ * The textual representation must have been previously written using an
+ * output stream whose imbued locale and whose type's template
+ * specialization arguments _CharT and _Traits were the same as those of
+ * @p __is.
+ *
+ * @param __is The input stream.
+ * @param __lcr A % linear_congruential random number generator.
+ * @returns __is.
+ */
+ template<class _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
+ _UIntType1 __m1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ linear_congruential<_UIntType1, __a1, __c1, __m1>& __lcr);
+
+ private:
+ template<class _Gen>
+ void
+ seed(_Gen& __g, true_type)
+ { return seed(static_cast<unsigned long>(__g)); }
+
+ template<class _Gen>
+ void
+ seed(_Gen& __g, false_type);
+
+ _UIntType _M_x;
+ };
+
+ /**
+ * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
+ */
+ typedef linear_congruential<unsigned long, 16807, 0, 2147483647> minstd_rand0;
+
+ /**
+ * An alternative LCR (Lehmer Generator function) .
+ */
+ typedef linear_congruential<unsigned long, 48271, 0, 2147483647> minstd_rand;
+
+
+ /**
+ * A generalized feedback shift register discrete random number generator.
+ *
+ * This algorithm avoids multiplication and division and is designed to be
+ * friendly to a pipelined architecture. If the parameters are chosen
+ * correctly, this generator will produce numbers with a very long period and
+ * fairly good apparent entropy, although still not cryptographically strong.
+ *
+ * The best way to use this generator is with the predefined mt19937 class.
+ *
+ * This algorithm was originally invented by Makoto Matsumoto and
+ * Takuji Nishimura.
+ *
+ * @var word_size The number of bits in each element of the state vector.
+ * @var state_size The degree of recursion.
+ * @var shift_size The period parameter.
+ * @var mask_bits The separation point bit index.
+ * @var parameter_a The last row of the twist matrix.
+ * @var output_u The first right-shift tempering matrix parameter.
+ * @var output_s The first left-shift tempering matrix parameter.
+ * @var output_b The first left-shift tempering matrix mask.
+ * @var output_t The second left-shift tempering matrix parameter.
+ * @var output_c The second left-shift tempering matrix mask.
+ * @var output_l The second right-shift tempering matrix parameter.
+ */
+ template<class _UIntType, int __w, int __n, int __m, int __r,
+ _UIntType __a, int __u, int __s, _UIntType __b, int __t,
+ _UIntType __c, int __l>
+ class mersenne_twister
+ {
+ __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
+
+ public:
+ // types
+ typedef _UIntType result_type;
+
+ // parameter values
+ static const int word_size = __w;
+ static const int state_size = __n;
+ static const int shift_size = __m;
+ static const int mask_bits = __r;
+ static const _UIntType parameter_a = __a;
+ static const int output_u = __u;
+ static const int output_s = __s;
+ static const _UIntType output_b = __b;
+ static const int output_t = __t;
+ static const _UIntType output_c = __c;
+ static const int output_l = __l;
+
+ // constructors and member function
+ mersenne_twister()
+ { seed(); }
+
+ explicit
+ mersenne_twister(unsigned long __value)
+ { seed(__value); }
+
+ template<class _Gen>
+ mersenne_twister(_Gen& __g)
+ { seed(__g); }
+
+ void
+ seed()
+ { seed(5489UL); }
+
+ void
+ seed(unsigned long __value);
+
+ template<class _Gen>
+ void
+ seed(_Gen& __g)
+ { seed(__g, typename is_fundamental<_Gen>::type()); }
+
+ result_type
+ min() const
+ { return 0; };
+
+ result_type
+ max() const
+ { return __detail::_Shift<_UIntType, __w>::__value - 1; }
+
+ result_type
+ operator()();
+
+ /**
+ * Compares two % mersenne_twister random number generator objects of
+ * the same type for equality.
+ *
+ * @param __lhs A % mersenne_twister random number generator object.
+ * @param __rhs Another % mersenne_twister random number generator
+ * object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const mersenne_twister& __lhs,
+ const mersenne_twister& __rhs)
+ { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
+
+ /**
+ * Compares two % mersenne_twister random number generator objects of
+ * the same type for inequality.
+ *
+ * @param __lhs A % mersenne_twister random number generator object.
+ * @param __rhs Another % mersenne_twister random number generator
+ * object.
+ *
+ * @returns true if the two objects are not equal, false otherwise.
+ */
+ friend bool
+ operator!=(const mersenne_twister& __lhs,
+ const mersenne_twister& __rhs)
+ { return !(__lhs == __rhs); }
+
+ /**
+ * Inserts the current state of a % mersenne_twister random number
+ * generator engine @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A % mersenne_twister random number generator engine.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<class _UIntType1, int __w1, int __n1, int __m1, int __r1,
+ _UIntType1 __a1, int __u1, int __s1, _UIntType1 __b1, int __t1,
+ _UIntType1 __c1, int __l1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1,
+ __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x);
+
+ /**
+ * Extracts the current state of a % mersenne_twister random number
+ * generator engine @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A % mersenne_twister random number generator engine.
+ *
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
+ */
+ template<class _UIntType1, int __w1, int __n1, int __m1, int __r1,
+ _UIntType1 __a1, int __u1, int __s1, _UIntType1 __b1, int __t1,
+ _UIntType1 __c1, int __l1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1,
+ __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x);
+
+ private:
+ template<class _Gen>
+ void
+ seed(_Gen& __g, true_type)
+ { return seed(static_cast<unsigned long>(__g)); }
+
+ template<class _Gen>
+ void
+ seed(_Gen& __g, false_type);
+
+ _UIntType _M_x[state_size];
+ int _M_p;
+ };
+
+ /**
+ * The classic Mersenne Twister.
+ *
+ * Reference:
+ * M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
+ * Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions
+ * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
+ */
+ typedef mersenne_twister<
+ unsigned long, 32, 624, 397, 31,
+ 0x9908b0dful, 11, 7,
+ 0x9d2c5680ul, 15,
+ 0xefc60000ul, 18
+ > mt19937;
+
+
+ /**
+ * @brief The Marsaglia-Zaman generator.
+ *
+ * This is a model of a Generalized Fibonacci discrete random number
+ * generator, sometimes referred to as the SWC generator.
+ *
+ * A discrete random number generator that produces pseudorandom
+ * numbers using @f$x_{i}\leftarrow(x_{i - s} - x_{i - r} -
+ * carry_{i-1}) \bmod m @f$.
+ *
+ * The size of the state is @f$ r @f$
+ * and the maximum period of the generator is @f$ m^r - m^s -1 @f$.
+ *
+ * N1688[4.13] says "the template parameter _IntType shall denote an integral
+ * type large enough to store values up to m."
+ *
+ * @var _M_x The state of the generator. This is a ring buffer.
+ * @var _M_carry The carry.
+ * @var _M_p Current index of x(i - r).
+ */
+ template<typename _IntType, _IntType __m, int __s, int __r>
+ class subtract_with_carry
+ {
+ __glibcxx_class_requires(_IntType, _IntegerConcept)
+
+ public:
+ /** The type of the generated random value. */
+ typedef _IntType result_type;
+
+ // parameter values
+ static const _IntType modulus = __m;
+ static const int long_lag = __r;
+ static const int short_lag = __s;
+
+ /**
+ * Constructs a default-initialized % subtract_with_carry random number
+ * generator.
+ */
+ subtract_with_carry()
+ { this->seed(); }
+
+ /**
+ * Constructs an explicitly seeded % subtract_with_carry random number
+ * generator.
+ */
+ explicit
+ subtract_with_carry(unsigned long __value)
+ { this->seed(__value); }
+
+ /**
+ * Constructs a %subtract_with_carry random number generator engine
+ * seeded from the generator function @p __g.
+ *
+ * @param __g The seed generator function.
+ */
+ template<class _Gen>
+ subtract_with_carry(_Gen& __g)
+ { this->seed(__g); }
+
+ /**
+ * Seeds the initial state @f$ x_0 @f$ of the random number generator.
+ *
+ * N1688[4.19] modifies this as follows. If @p __value == 0,
+ * sets value to 19780503. In any case, with a linear
+ * congruential generator lcg(i) having parameters @f$ m_{lcg} =
+ * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
+ * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
+ * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
+ * set carry to 1, otherwise sets carry to 0.
+ */
+ void
+ seed(unsigned long __value = 19780503);
+
+ /**
+ * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry
+ * random number generator.
+ */
+ template<class _Gen>
+ void
+ seed(_Gen& __g)
+ { seed(__g, typename is_fundamental<_Gen>::type()); }
+
+ /**
+ * Gets the inclusive minimum value of the range of random integers
+ * returned by this generator.
+ */
+ result_type
+ min() const
+ { return 0; }
+
+ /**
+ * Gets the inclusive maximum value of the range of random integers
+ * returned by this generator.
+ */
+ result_type
+ max() const
+ { return this->modulus - 1; }
+
+ /**
+ * Gets the next random number in the sequence.
+ */
+ result_type
+ operator()();
+
+ /**
+ * Compares two % subtract_with_carry random number generator objects of
+ * the same type for equality.
+ *
+ * @param __lhs A % subtract_with_carry random number generator object.
+ * @param __rhs Another % subtract_with_carry random number generator
+ * object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const subtract_with_carry& __lhs,
+ const subtract_with_carry& __rhs)
+ { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
+
+ /**
+ * Compares two % subtract_with_carry random number generator objects of
+ * the same type for inequality.
+ *
+ * @param __lhs A % subtract_with_carry random number generator object.
+ * @param __rhs Another % subtract_with_carry random number generator
+ * object.
+ *
+ * @returns true if the two objects are not equal, false otherwise.
+ */
+ friend bool
+ operator!=(const subtract_with_carry& __lhs,
+ const subtract_with_carry& __rhs)
+ { return !(__lhs == __rhs); }
+
+ /**
+ * Inserts the current state of a % subtract_with_carry random number
+ * generator engine @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A % subtract_with_carry random number generator engine.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _IntType1, _IntType1 __m1, int __s1, int __r1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const subtract_with_carry<_IntType1, __m1, __s1,
+ __r1>& __x);
+
+ /**
+ * Extracts the current state of a % subtract_with_carry random number
+ * generator engine @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A % subtract_with_carry random number generator engine.
+ *
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
+ */
+ template<typename _IntType1, _IntType1 __m1, int __s1, int __r1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ subtract_with_carry<_IntType1, __m1, __s1, __r1>& __x);
+
+ private:
+ template<class _Gen>
+ void
+ seed(_Gen& __g, true_type)
+ { return seed(static_cast<unsigned long>(__g)); }
+
+ template<class _Gen>
+ void
+ seed(_Gen& __g, false_type);
+
+ typedef typename __gnu_cxx::__add_unsigned<_IntType>::__type _UIntType;
+
+ _UIntType _M_x[long_lag];
+ _UIntType _M_carry;
+ int _M_p;
+ };
+
+
+ /**
+ * @brief The Marsaglia-Zaman generator (floats version).
+ *
+ * @var _M_x The state of the generator. This is a ring buffer.
+ * @var _M_carry The carry.
+ * @var _M_p Current index of x(i - r).
+ * @var _M_npows Precomputed negative powers of 2.
+ */
+ template<typename _RealType, int __w, int __s, int __r>
+ class subtract_with_carry_01
+ {
+ public:
+ /** The type of the generated random value. */
+ typedef _RealType result_type;
+
+ // parameter values
+ static const int word_size = __w;
+ static const int long_lag = __r;
+ static const int short_lag = __s;
+
+ /**
+ * Constructs a default-initialized % subtract_with_carry_01 random
+ * number generator.
+ */
+ subtract_with_carry_01()
+ {
+ this->seed();
+ _M_initialize_npows();
+ }
+
+ /**
+ * Constructs an explicitly seeded % subtract_with_carry_01 random number
+ * generator.
+ */
+ explicit
+ subtract_with_carry_01(unsigned long __value)
+ {
+ this->seed(__value);
+ _M_initialize_npows();
+ }
+
+ /**
+ * Constructs a % subtract_with_carry_01 random number generator engine
+ * seeded from the generator function @p __g.
+ *
+ * @param __g The seed generator function.
+ */
+ template<class _Gen>
+ subtract_with_carry_01(_Gen& __g)
+ {
+ this->seed(__g);
+ _M_initialize_npows();
+ }
+
+ /**
+ * Seeds the initial state @f$ x_0 @f$ of the random number generator.
+ */
+ void
+ seed(unsigned long __value = 19780503);
+
+ /**
+ * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry_01
+ * random number generator.
+ */
+ template<class _Gen>
+ void
+ seed(_Gen& __g)
+ { seed(__g, typename is_fundamental<_Gen>::type()); }
+
+ /**
+ * Gets the minimum value of the range of random floats
+ * returned by this generator.
+ */
+ result_type
+ min() const
+ { return 0.0; }
+
+ /**
+ * Gets the maximum value of the range of random floats
+ * returned by this generator.
+ */
+ result_type
+ max() const
+ { return 1.0; }
+
+ /**
+ * Gets the next random number in the sequence.
+ */
+ result_type
+ operator()();
+
+ /**
+ * Compares two % subtract_with_carry_01 random number generator objects
+ * of the same type for equality.
+ *
+ * @param __lhs A % subtract_with_carry_01 random number
+ * generator object.
+ * @param __rhs Another % subtract_with_carry_01 random number generator
+ * object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const subtract_with_carry_01& __lhs,
+ const subtract_with_carry_01& __rhs)
+ {
+ for (int __i = 0; __i < long_lag; ++__i)
+ if (!std::equal(__lhs._M_x[__i], __lhs._M_x[__i] + __n,
+ __rhs._M_x[__i]))
+ return false;
+ return true;
+ }
+
+ /**
+ * Compares two % subtract_with_carry_01 random number generator objects
+ * of the same type for inequality.
+ *
+ * @param __lhs A % subtract_with_carry_01 random number
+ * generator object.
+ *
+ * @param __rhs Another % subtract_with_carry_01 random number generator
+ * object.
+ *
+ * @returns true if the two objects are not equal, false otherwise.
+ */
+ friend bool
+ operator!=(const subtract_with_carry_01& __lhs,
+ const subtract_with_carry_01& __rhs)
+ { return !(__lhs == __rhs); }
+
+ /**
+ * Inserts the current state of a % subtract_with_carry_01 random number
+ * generator engine @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A % subtract_with_carry_01 random number generator engine.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType1, int __w1, int __s1, int __r1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const subtract_with_carry_01<_RealType1, __w1, __s1,
+ __r1>& __x);
+
+ /**
+ * Extracts the current state of a % subtract_with_carry_01 random number
+ * generator engine @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A % subtract_with_carry_01 random number generator engine.
+ *
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
+ */
+ template<typename _RealType1, int __w1, int __s1, int __r1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ subtract_with_carry_01<_RealType1, __w1, __s1, __r1>& __x);
+
+ private:
+ template<class _Gen>
+ void
+ seed(_Gen& __g, true_type)
+ { return seed(static_cast<unsigned long>(__g)); }
+
+ template<class _Gen>
+ void
+ seed(_Gen& __g, false_type);
+
+ void
+ _M_initialize_npows();
+
+ static const int __n = (__w + 31) / 32;
+
+ typedef __detail::_UInt32Type _UInt32Type;
+ _UInt32Type _M_x[long_lag][__n];
+ _RealType _M_npows[__n];
+ _UInt32Type _M_carry;
+ int _M_p;
+ };
+
+ typedef subtract_with_carry_01<float, 24, 10, 24> ranlux_base_01;
+
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 508. Bad parameters for ranlux64_base_01.
+ typedef subtract_with_carry_01<double, 48, 5, 12> ranlux64_base_01;
+
+
+ /**
+ * Produces random numbers from some base engine by discarding blocks of
+ * data.
+ *
+ * 0 <= @p __r <= @p __p
+ */
+ template<class _UniformRandomNumberGenerator, int __p, int __r>
+ class discard_block
+ {
+ // __glibcxx_class_requires(typename base_type::result_type,
+ // ArithmeticTypeConcept)
+
+ public:
+ /** The type of the underlying generator engine. */
+ typedef _UniformRandomNumberGenerator base_type;
+ /** The type of the generated random value. */
+ typedef typename base_type::result_type result_type;
+
+ // parameter values
+ static const int block_size = __p;
+ static const int used_block = __r;
+
+ /**
+ * Constructs a default %discard_block engine.
+ *
+ * The underlying engine is default constructed as well.
+ */
+ discard_block()
+ : _M_n(0) { }
+
+ /**
+ * Copy constructs a %discard_block engine.
+ *
+ * Copies an existing base class random number generator.
+ * @param rng An existing (base class) engine object.
+ */
+ explicit
+ discard_block(const base_type& __rng)
+ : _M_b(__rng), _M_n(0) { }
+
+ /**
+ * Seed constructs a %discard_block engine.
+ *
+ * Constructs the underlying generator engine seeded with @p __s.
+ * @param __s A seed value for the base class engine.
+ */
+ explicit
+ discard_block(unsigned long __s)
+ : _M_b(__s), _M_n(0) { }
+
+ /**
+ * Generator construct a %discard_block engine.
+ *
+ * @param __g A seed generator function.
+ */
+ template<class _Gen>
+ discard_block(_Gen& __g)
+ : _M_b(__g), _M_n(0) { }
+
+ /**
+ * Reseeds the %discard_block object with the default seed for the
+ * underlying base class generator engine.
+ */
+ void seed()
+ {
+ _M_b.seed();
+ _M_n = 0;
+ }
+
+ /**
+ * Reseeds the %discard_block object with the given seed generator
+ * function.
+ * @param __g A seed generator function.
+ */
+ template<class _Gen>
+ void seed(_Gen& __g)
+ {
+ _M_b.seed(__g);
+ _M_n = 0;
+ }
+
+ /**
+ * Gets a const reference to the underlying generator engine object.
+ */
+ const base_type&
+ base() const
+ { return _M_b; }
+
+ /**
+ * Gets the minimum value in the generated random number range.
+ */
+ result_type
+ min() const
+ { return _M_b.min(); }
+
+ /**
+ * Gets the maximum value in the generated random number range.
+ */
+ result_type
+ max() const
+ { return _M_b.max(); }
+
+ /**
+ * Gets the next value in the generated random number sequence.
+ */
+ result_type
+ operator()();
+
+ /**
+ * Compares two %discard_block random number generator objects of
+ * the same type for equality.
+ *
+ * @param __lhs A %discard_block random number generator object.
+ * @param __rhs Another %discard_block random number generator
+ * object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const discard_block& __lhs, const discard_block& __rhs)
+ { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); }
+
+ /**
+ * Compares two %discard_block random number generator objects of
+ * the same type for inequality.
+ *
+ * @param __lhs A %discard_block random number generator object.
+ * @param __rhs Another %discard_block random number generator
+ * object.
+ *
+ * @returns true if the two objects are not equal, false otherwise.
+ */
+ friend bool
+ operator!=(const discard_block& __lhs, const discard_block& __rhs)
+ { return !(__lhs == __rhs); }
+
+ /**
+ * Inserts the current state of a %discard_block random number
+ * generator engine @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %discard_block random number generator engine.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<class _UniformRandomNumberGenerator1, int __p1, int __r1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const discard_block<_UniformRandomNumberGenerator1,
+ __p1, __r1>& __x);
+
+ /**
+ * Extracts the current state of a % subtract_with_carry random number
+ * generator engine @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %discard_block random number generator engine.
+ *
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
+ */
+ template<class _UniformRandomNumberGenerator1, int __p1, int __r1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ discard_block<_UniformRandomNumberGenerator1,
+ __p1, __r1>& __x);
+
+ private:
+ base_type _M_b;
+ int _M_n;
+ };
+
+
+ /**
+ * James's luxury-level-3 integer adaptation of Luescher's generator.
+ */
+ typedef discard_block<
+ subtract_with_carry<unsigned long, (1UL << 24), 10, 24>,
+ 223,
+ 24
+ > ranlux3;
+
+ /**
+ * James's luxury-level-4 integer adaptation of Luescher's generator.
+ */
+ typedef discard_block<
+ subtract_with_carry<unsigned long, (1UL << 24), 10, 24>,
+ 389,
+ 24
+ > ranlux4;
+
+ typedef discard_block<
+ subtract_with_carry_01<float, 24, 10, 24>,
+ 223,
+ 24
+ > ranlux3_01;
+
+ typedef discard_block<
+ subtract_with_carry_01<float, 24, 10, 24>,
+ 389,
+ 24
+ > ranlux4_01;
+
+
+ /**
+ * A random number generator adaptor class that combines two random number
+ * generator engines into a single output sequence.
+ */
+ template<class _UniformRandomNumberGenerator1, int __s1,
+ class _UniformRandomNumberGenerator2, int __s2>
+ class xor_combine
+ {
+ // __glibcxx_class_requires(typename _UniformRandomNumberGenerator1::
+ // result_type, ArithmeticTypeConcept)
+ // __glibcxx_class_requires(typename _UniformRandomNumberGenerator2::
+ // result_type, ArithmeticTypeConcept)
+
+ public:
+ /** The type of the first underlying generator engine. */
+ typedef _UniformRandomNumberGenerator1 base1_type;
+ /** The type of the second underlying generator engine. */
+ typedef _UniformRandomNumberGenerator2 base2_type;
+
+ private:
+ typedef typename base1_type::result_type _Result_type1;
+ typedef typename base2_type::result_type _Result_type2;
+
+ public:
+ /** The type of the generated random value. */
+ typedef typename __gnu_cxx::__conditional_type<(sizeof(_Result_type1)
+ > sizeof(_Result_type2)),
+ _Result_type1, _Result_type2>::__type result_type;
+
+ // parameter values
+ static const int shift1 = __s1;
+ static const int shift2 = __s2;
+
+ // constructors and member function
+ xor_combine()
+ : _M_b1(), _M_b2()
+ { _M_initialize_max(); }
+
+ xor_combine(const base1_type& __rng1, const base2_type& __rng2)
+ : _M_b1(__rng1), _M_b2(__rng2)
+ { _M_initialize_max(); }
+
+ xor_combine(unsigned long __s)
+ : _M_b1(__s), _M_b2(__s + 1)
+ { _M_initialize_max(); }
+
+ template<class _Gen>
+ xor_combine(_Gen& __g)
+ : _M_b1(__g), _M_b2(__g)
+ { _M_initialize_max(); }
+
+ void
+ seed()
+ {
+ _M_b1.seed();
+ _M_b2.seed();
+ }
+
+ template<class _Gen>
+ void
+ seed(_Gen& __g)
+ {
+ _M_b1.seed(__g);
+ _M_b2.seed(__g);
+ }
+
+ const base1_type&
+ base1() const
+ { return _M_b1; }
+
+ const base2_type&
+ base2() const
+ { return _M_b2; }
+
+ result_type
+ min() const
+ { return 0; }
+
+ result_type
+ max() const
+ { return _M_max; }
+
+ /**
+ * Gets the next random number in the sequence.
+ */
+ // NB: Not exactly the TR1 formula, per N2079 instead.
+ result_type
+ operator()()
+ {
+ return ((result_type(_M_b1() - _M_b1.min()) << shift1)
+ ^ (result_type(_M_b2() - _M_b2.min()) << shift2));
+ }
+
+ /**
+ * Compares two %xor_combine random number generator objects of
+ * the same type for equality.
+ *
+ * @param __lhs A %xor_combine random number generator object.
+ * @param __rhs Another %xor_combine random number generator
+ * object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const xor_combine& __lhs, const xor_combine& __rhs)
+ {
+ return (__lhs.base1() == __rhs.base1())
+ && (__lhs.base2() == __rhs.base2());
+ }
+
+ /**
+ * Compares two %xor_combine random number generator objects of
+ * the same type for inequality.
+ *
+ * @param __lhs A %xor_combine random number generator object.
+ * @param __rhs Another %xor_combine random number generator
+ * object.
+ *
+ * @returns true if the two objects are not equal, false otherwise.
+ */
+ friend bool
+ operator!=(const xor_combine& __lhs, const xor_combine& __rhs)
+ { return !(__lhs == __rhs); }
+
+ /**
+ * Inserts the current state of a %xor_combine random number
+ * generator engine @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %xor_combine random number generator engine.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<class _UniformRandomNumberGenerator11, int __s11,
+ class _UniformRandomNumberGenerator21, int __s21,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const xor_combine<_UniformRandomNumberGenerator11, __s11,
+ _UniformRandomNumberGenerator21, __s21>& __x);
+
+ /**
+ * Extracts the current state of a %xor_combine random number
+ * generator engine @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %xor_combine random number generator engine.
+ *
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
+ */
+ template<class _UniformRandomNumberGenerator11, int __s11,
+ class _UniformRandomNumberGenerator21, int __s21,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ xor_combine<_UniformRandomNumberGenerator11, __s11,
+ _UniformRandomNumberGenerator21, __s21>& __x);
+
+ private:
+ void
+ _M_initialize_max();
+
+ result_type
+ _M_initialize_max_aux(result_type, result_type, int);
+
+ base1_type _M_b1;
+ base2_type _M_b2;
+ result_type _M_max;
+ };
+
+
+ /**
+ * A standard interface to a platform-specific non-deterministic
+ * random number generator (if any are available).
+ */
+ class random_device
+ {
+ public:
+ // types
+ typedef unsigned int result_type;
+
+ // constructors, destructors and member functions
+
+#ifdef _GLIBCXX_USE_RANDOM_TR1
+
+ explicit
+ random_device(const std::string& __token = "/dev/urandom")
+ {
+ if ((__token != "/dev/urandom" && __token != "/dev/random")
+ || !(_M_file = std::fopen(__token.c_str(), "rb")))
+ std::__throw_runtime_error(__N("random_device::"
+ "random_device(const std::string&)"));
+ }
+
+ ~random_device()
+ { std::fclose(_M_file); }
+
+#else
+
+ explicit
+ random_device(const std::string& __token = "mt19937")
+ : _M_mt(_M_strtoul(__token)) { }
+
+ private:
+ static unsigned long
+ _M_strtoul(const std::string& __str)
+ {
+ unsigned long __ret = 5489UL;
+ if (__str != "mt19937")
+ {
+ const char* __nptr = __str.c_str();
+ char* __endptr;
+ __ret = std::strtoul(__nptr, &__endptr, 0);
+ if (*__nptr == '\0' || *__endptr != '\0')
+ std::__throw_runtime_error(__N("random_device::_M_strtoul"
+ "(const std::string&)"));
+ }
+ return __ret;
+ }
+
+ public:
+
+#endif
+
+ result_type
+ min() const
+ { return std::numeric_limits<result_type>::min(); }
+
+ result_type
+ max() const
+ { return std::numeric_limits<result_type>::max(); }
+
+ double
+ entropy() const
+ { return 0.0; }
+
+ result_type
+ operator()()
+ {
+#ifdef _GLIBCXX_USE_RANDOM_TR1
+ result_type __ret;
+ std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
+ 1, _M_file);
+ return __ret;
+#else
+ return _M_mt();
+#endif
+ }
+
+ private:
+ random_device(const random_device&);
+ void operator=(const random_device&);
+
+#ifdef _GLIBCXX_USE_RANDOM_TR1
+ FILE* _M_file;
+#else
+ mt19937 _M_mt;
+#endif
+ };
+
+ /* @} */ // group tr1_random_generators
+
+ /**
+ * @addtogroup tr1_random_distributions Random Number Distributions
+ * @ingroup tr1_random
+ * @{
+ */
+
+ /**
+ * @addtogroup tr1_random_distributions_discrete Discrete Distributions
+ * @ingroup tr1_random_distributions
+ * @{
+ */
+
+ /**
+ * @brief Uniform discrete distribution for random numbers.
+ * A discrete random distribution on the range @f$[min, max]@f$ with equal
+ * probability throughout the range.
+ */
+ template<typename _IntType = int>
+ class uniform_int
+ {
+ __glibcxx_class_requires(_IntType, _IntegerConcept)
+
+ public:
+ /** The type of the parameters of the distribution. */
+ typedef _IntType input_type;
+ /** The type of the range of the distribution. */
+ typedef _IntType result_type;
+
+ public:
+ /**
+ * Constructs a uniform distribution object.
+ */
+ explicit
+ uniform_int(_IntType __min = 0, _IntType __max = 9)
+ : _M_min(__min), _M_max(__max)
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max);
+ }
+
+ /**
+ * Gets the inclusive lower bound of the distribution range.
+ */
+ result_type
+ min() const
+ { return _M_min; }
+
+ /**
+ * Gets the inclusive upper bound of the distribution range.
+ */
+ result_type
+ max() const
+ { return _M_max; }
+
+ /**
+ * Resets the distribution state.
+ *
+ * Does nothing for the uniform integer distribution.
+ */
+ void
+ reset() { }
+
+ /**
+ * Gets a uniformly distributed random number in the range
+ * @f$(min, max)@f$.
+ */
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ {
+ typedef typename _UniformRandomNumberGenerator::result_type
+ _UResult_type;
+ return _M_call(__urng, _M_min, _M_max,
+ typename is_integral<_UResult_type>::type());
+ }
+
+ /**
+ * Gets a uniform random number in the range @f$[0, n)@f$.
+ *
+ * This function is aimed at use with std::random_shuffle.
+ */
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng, result_type __n)
+ {
+ typedef typename _UniformRandomNumberGenerator::result_type
+ _UResult_type;
+ return _M_call(__urng, 0, __n - 1,
+ typename is_integral<_UResult_type>::type());
+ }
+
+ /**
+ * Inserts a %uniform_int random number distribution @p __x into the
+ * output stream @p os.
+ *
+ * @param __os An output stream.
+ * @param __x A %uniform_int random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _IntType1, typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const uniform_int<_IntType1>& __x);
+
+ /**
+ * Extracts a %uniform_int random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %uniform_int random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _IntType1, typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ uniform_int<_IntType1>& __x);
+
+ private:
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ _M_call(_UniformRandomNumberGenerator& __urng,
+ result_type __min, result_type __max, true_type);
+
+ template<typename _UniformRandomNumberGenerator>
+ result_type
+ _M_call(_UniformRandomNumberGenerator& __urng,
+ result_type __min, result_type __max, false_type)
+ {
+ return result_type((__urng() - __urng.min())
+ / (__urng.max() - __urng.min())
+ * (__max - __min + 1)) + __min;
+ }
+
+ _IntType _M_min;
+ _IntType _M_max;
+ };
+
+
+ /**
+ * @brief A Bernoulli random number distribution.
+ *
+ * Generates a sequence of true and false values with likelihood @f$ p @f$
+ * that true will come up and @f$ (1 - p) @f$ that false will appear.
+ */
+ class bernoulli_distribution
+ {
+ public:
+ typedef int input_type;
+ typedef bool result_type;
+
+ public:
+ /**
+ * Constructs a Bernoulli distribution with likelihood @p p.
+ *
+ * @param __p [IN] The likelihood of a true result being returned. Must
+ * be in the interval @f$ [0, 1] @f$.
+ */
+ explicit
+ bernoulli_distribution(double __p = 0.5)
+ : _M_p(__p)
+ {
+ _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
+ }
+
+ /**
+ * Gets the @p p parameter of the distribution.
+ */
+ double
+ p() const
+ { return _M_p; }
+
+ /**
+ * Resets the distribution state.
+ *
+ * Does nothing for a Bernoulli distribution.
+ */
+ void
+ reset() { }
+
+ /**
+ * Gets the next value in the Bernoullian sequence.
+ */
+ template<class _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ {
+ if ((__urng() - __urng.min()) < _M_p * (__urng.max() - __urng.min()))
+ return true;
+ return false;
+ }
+
+ /**
+ * Inserts a %bernoulli_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %bernoulli_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const bernoulli_distribution& __x);
+
+ /**
+ * Extracts a %bernoulli_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %bernoulli_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ bernoulli_distribution& __x)
+ { return __is >> __x._M_p; }
+
+ private:
+ double _M_p;
+ };
+
+
+ /**
+ * @brief A discrete geometric random number distribution.
+ *
+ * The formula for the geometric probability mass function is
+ * @f$ p(i) = (1 - p)p^{i-1} @f$ where @f$ p @f$ is the parameter of the
+ * distribution.
+ */
+ template<typename _IntType = int, typename _RealType = double>
+ class geometric_distribution
+ {
+ public:
+ // types
+ typedef _RealType input_type;
+ typedef _IntType result_type;
+
+ // constructors and member function
+ explicit
+ geometric_distribution(const _RealType& __p = _RealType(0.5))
+ : _M_p(__p)
+ {
+ _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0));
+ _M_initialize();
+ }
+
+ /**
+ * Gets the distribution parameter @p p.
+ */
+ _RealType
+ p() const
+ { return _M_p; }
+
+ void
+ reset() { }
+
+ template<class _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng);
+
+ /**
+ * Inserts a %geometric_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %geometric_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _IntType1, typename _RealType1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const geometric_distribution<_IntType1, _RealType1>& __x);
+
+ /**
+ * Extracts a %geometric_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %geometric_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ geometric_distribution& __x)
+ {
+ __is >> __x._M_p;
+ __x._M_initialize();
+ return __is;
+ }
+
+ private:
+ void
+ _M_initialize()
+ { _M_log_p = std::log(_M_p); }
+
+ _RealType _M_p;
+ _RealType _M_log_p;
+ };
+
+
+ template<typename _RealType>
+ class normal_distribution;
+
+ /**
+ * @brief A discrete Poisson random number distribution.
+ *
+ * The formula for the Poisson probability mass function is
+ * @f$ p(i) = \frac{mean^i}{i!} e^{-mean} @f$ where @f$ mean @f$ is the
+ * parameter of the distribution.
+ */
+ template<typename _IntType = int, typename _RealType = double>
+ class poisson_distribution
+ {
+ public:
+ // types
+ typedef _RealType input_type;
+ typedef _IntType result_type;
+
+ // constructors and member function
+ explicit
+ poisson_distribution(const _RealType& __mean = _RealType(1))
+ : _M_mean(__mean), _M_nd()
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
+ _M_initialize();
+ }
+
+ /**
+ * Gets the distribution parameter @p mean.
+ */
+ _RealType
+ mean() const
+ { return _M_mean; }
+
+ void
+ reset()
+ { _M_nd.reset(); }
+
+ template<class _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng);
+
+ /**
+ * Inserts a %poisson_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %poisson_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _IntType1, typename _RealType1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const poisson_distribution<_IntType1, _RealType1>& __x);
+
+ /**
+ * Extracts a %poisson_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %poisson_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _IntType1, typename _RealType1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ poisson_distribution<_IntType1, _RealType1>& __x);
+
+ private:
+ void
+ _M_initialize();
+
+ // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
+ normal_distribution<_RealType> _M_nd;
+
+ _RealType _M_mean;
+
+ // Hosts either log(mean) or the threshold of the simple method.
+ _RealType _M_lm_thr;
+#if _GLIBCXX_USE_C99_MATH_TR1
+ _RealType _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
+#endif
+ };
+
+
+ /**
+ * @brief A discrete binomial random number distribution.
+ *
+ * The formula for the binomial probability mass function is
+ * @f$ p(i) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$
+ * and @f$ p @f$ are the parameters of the distribution.
+ */
+ template<typename _IntType = int, typename _RealType = double>
+ class binomial_distribution
+ {
+ public:
+ // types
+ typedef _RealType input_type;
+ typedef _IntType result_type;
+
+ // constructors and member function
+ explicit
+ binomial_distribution(_IntType __t = 1,
+ const _RealType& __p = _RealType(0.5))
+ : _M_t(__t), _M_p(__p), _M_nd()
+ {
+ _GLIBCXX_DEBUG_ASSERT((_M_t >= 0) && (_M_p >= 0.0) && (_M_p <= 1.0));
+ _M_initialize();
+ }
+
+ /**
+ * Gets the distribution @p t parameter.
+ */
+ _IntType
+ t() const
+ { return _M_t; }
+
+ /**
+ * Gets the distribution @p p parameter.
+ */
+ _RealType
+ p() const
+ { return _M_p; }
+
+ void
+ reset()
+ { _M_nd.reset(); }
+
+ template<class _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng);
+
+ /**
+ * Inserts a %binomial_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %binomial_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _IntType1, typename _RealType1,
+ typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const binomial_distribution<_IntType1, _RealType1>& __x);
+
+ /**
+ * Extracts a %binomial_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %binomial_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _IntType1, typename _RealType1,
+ typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ binomial_distribution<_IntType1, _RealType1>& __x);
+
+ private:
+ void
+ _M_initialize();
+
+ template<class _UniformRandomNumberGenerator>
+ result_type
+ _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
+
+ // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
+ normal_distribution<_RealType> _M_nd;
+
+ _RealType _M_q;
+#if _GLIBCXX_USE_C99_MATH_TR1
+ _RealType _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
+ _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
+#endif
+ _RealType _M_p;
+ _IntType _M_t;
+
+ bool _M_easy;
+ };
+
+ /* @} */ // group tr1_random_distributions_discrete
+
+ /**
+ * @addtogroup tr1_random_distributions_continuous Continuous Distributions
+ * @ingroup tr1_random_distributions
+ * @{
+ */
+
+ /**
+ * @brief Uniform continuous distribution for random numbers.
+ *
+ * A continuous random distribution on the range [min, max) with equal
+ * probability throughout the range. The URNG should be real-valued and
+ * deliver number in the range [0, 1).
+ */
+ template<typename _RealType = double>
+ class uniform_real
+ {
+ public:
+ // types
+ typedef _RealType input_type;
+ typedef _RealType result_type;
+
+ public:
+ /**
+ * Constructs a uniform_real object.
+ *
+ * @param __min [IN] The lower bound of the distribution.
+ * @param __max [IN] The upper bound of the distribution.
+ */
+ explicit
+ uniform_real(_RealType __min = _RealType(0),
+ _RealType __max = _RealType(1))
+ : _M_min(__min), _M_max(__max)
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max);
+ }
+
+ result_type
+ min() const
+ { return _M_min; }
+
+ result_type
+ max() const
+ { return _M_max; }
+
+ void
+ reset() { }
+
+ template<class _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return (__urng() * (_M_max - _M_min)) + _M_min; }
+
+ /**
+ * Inserts a %uniform_real random number distribution @p __x into the
+ * output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %uniform_real random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType1, typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const uniform_real<_RealType1>& __x);
+
+ /**
+ * Extracts a %uniform_real random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %uniform_real random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _RealType1, typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ uniform_real<_RealType1>& __x);
+
+ private:
+ _RealType _M_min;
+ _RealType _M_max;
+ };
+
+
+ /**
+ * @brief An exponential continuous distribution for random numbers.
+ *
+ * The formula for the exponential probability mass function is
+ * @f$ p(x) = \lambda e^{-\lambda x} @f$.
+ *
+ * <table border=1 cellpadding=10 cellspacing=0>
+ * <caption align=top>Distribution Statistics</caption>
+ * <tr><td>Mean</td><td>@f$ \frac{1}{\lambda} @f$</td></tr>
+ * <tr><td>Median</td><td>@f$ \frac{\ln 2}{\lambda} @f$</td></tr>
+ * <tr><td>Mode</td><td>@f$ zero @f$</td></tr>
+ * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
+ * <tr><td>Standard Deviation</td><td>@f$ \frac{1}{\lambda} @f$</td></tr>
+ * </table>
+ */
+ template<typename _RealType = double>
+ class exponential_distribution
+ {
+ public:
+ // types
+ typedef _RealType input_type;
+ typedef _RealType result_type;
+
+ public:
+ /**
+ * Constructs an exponential distribution with inverse scale parameter
+ * @f$ \lambda @f$.
+ */
+ explicit
+ exponential_distribution(const result_type& __lambda = result_type(1))
+ : _M_lambda(__lambda)
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_lambda > 0);
+ }
+
+ /**
+ * Gets the inverse scale parameter of the distribution.
+ */
+ _RealType
+ lambda() const
+ { return _M_lambda; }
+
+ /**
+ * Resets the distribution.
+ *
+ * Has no effect on exponential distributions.
+ */
+ void
+ reset() { }
+
+ template<class _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng)
+ { return -std::log(__urng()) / _M_lambda; }
+
+ /**
+ * Inserts a %exponential_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %exponential_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType1, typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const exponential_distribution<_RealType1>& __x);
+
+ /**
+ * Extracts a %exponential_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %exponential_distribution random number
+ * generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ exponential_distribution& __x)
+ { return __is >> __x._M_lambda; }
+
+ private:
+ result_type _M_lambda;
+ };
+
+
+ /**
+ * @brief A normal continuous distribution for random numbers.
+ *
+ * The formula for the normal probability mass function is
+ * @f$ p(x) = \frac{1}{\sigma \sqrt{2 \pi}}
+ * e^{- \frac{{x - mean}^ {2}}{2 \sigma ^ {2}} } @f$.
+ */
+ template<typename _RealType = double>
+ class normal_distribution
+ {
+ public:
+ // types
+ typedef _RealType input_type;
+ typedef _RealType result_type;
+
+ public:
+ /**
+ * Constructs a normal distribution with parameters @f$ mean @f$ and
+ * @f$ \sigma @f$.
+ */
+ explicit
+ normal_distribution(const result_type& __mean = result_type(0),
+ const result_type& __sigma = result_type(1))
+ : _M_mean(__mean), _M_sigma(__sigma), _M_saved_available(false)
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_sigma > 0);
+ }
+
+ /**
+ * Gets the mean of the distribution.
+ */
+ _RealType
+ mean() const
+ { return _M_mean; }
+
+ /**
+ * Gets the @f$ \sigma @f$ of the distribution.
+ */
+ _RealType
+ sigma() const
+ { return _M_sigma; }
+
+ /**
+ * Resets the distribution.
+ */
+ void
+ reset()
+ { _M_saved_available = false; }
+
+ template<class _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng);
+
+ /**
+ * Inserts a %normal_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %normal_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType1, typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const normal_distribution<_RealType1>& __x);
+
+ /**
+ * Extracts a %normal_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %normal_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _RealType1, typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ normal_distribution<_RealType1>& __x);
+
+ private:
+ result_type _M_mean;
+ result_type _M_sigma;
+ result_type _M_saved;
+ bool _M_saved_available;
+ };
+
+
+ /**
+ * @brief A gamma continuous distribution for random numbers.
+ *
+ * The formula for the gamma probability mass function is
+ * @f$ p(x) = \frac{1}{\Gamma(\alpha)} x^{\alpha - 1} e^{-x} @f$.
+ */
+ template<typename _RealType = double>
+ class gamma_distribution
+ {
+ public:
+ // types
+ typedef _RealType input_type;
+ typedef _RealType result_type;
+
+ public:
+ /**
+ * Constructs a gamma distribution with parameters @f$ \alpha @f$.
+ */
+ explicit
+ gamma_distribution(const result_type& __alpha_val = result_type(1))
+ : _M_alpha(__alpha_val)
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_alpha > 0);
+ _M_initialize();
+ }
+
+ /**
+ * Gets the @f$ \alpha @f$ of the distribution.
+ */
+ _RealType
+ alpha() const
+ { return _M_alpha; }
+
+ /**
+ * Resets the distribution.
+ */
+ void
+ reset() { }
+
+ template<class _UniformRandomNumberGenerator>
+ result_type
+ operator()(_UniformRandomNumberGenerator& __urng);
+
+ /**
+ * Inserts a %gamma_distribution random number distribution
+ * @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A %gamma_distribution random number distribution.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _RealType1, typename _CharT, typename _Traits>
+ friend std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const gamma_distribution<_RealType1>& __x);
+
+ /**
+ * Extracts a %gamma_distribution random number distribution
+ * @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A %gamma_distribution random number generator engine.
+ *
+ * @returns The input stream with @p __x extracted or in an error state.
+ */
+ template<typename _CharT, typename _Traits>
+ friend std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ gamma_distribution& __x)
+ {
+ __is >> __x._M_alpha;
+ __x._M_initialize();
+ return __is;
+ }
+
+ private:
+ void
+ _M_initialize();
+
+ result_type _M_alpha;
+
+ // Hosts either lambda of GB or d of modified Vaduva's.
+ result_type _M_l_d;
+ };
+
+ /* @} */ // group tr1_random_distributions_continuous
+ /* @} */ // group tr1_random_distributions
+ /* @} */ // group tr1_random
+
+}
+}
+
+#include <tr1/random.tcc>
+
+#endif // _GLIBCXX_TR1_RANDOM_H
diff --git a/libstdc++-v3/include/tr1/random.tcc b/libstdc++-v3/include/tr1/random.tcc
new file mode 100644
index 00000000000..ec06ae31a6c
--- /dev/null
+++ b/libstdc++-v3/include/tr1/random.tcc
@@ -0,0 +1,1583 @@
+// random number generation (out of line) -*- C++ -*-
+
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/** @file tr1/random.tcc
+ * This is an internal header file, included by other library headers.
+ * You should not attempt to use it directly.
+ */
+
+namespace std
+{
+namespace tr1
+{
+
+ /*
+ * (Further) implementation-space details.
+ */
+ namespace __detail
+ {
+ // General case for x = (ax + c) mod m -- use Schrage's algorithm to avoid
+ // integer overflow.
+ //
+ // Because a and c are compile-time integral constants the compiler kindly
+ // elides any unreachable paths.
+ //
+ // Preconditions: a > 0, m > 0.
+ //
+ template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool>
+ struct _Mod
+ {
+ static _Tp
+ __calc(_Tp __x)
+ {
+ if (__a == 1)
+ __x %= __m;
+ else
+ {
+ static const _Tp __q = __m / __a;
+ static const _Tp __r = __m % __a;
+
+ _Tp __t1 = __a * (__x % __q);
+ _Tp __t2 = __r * (__x / __q);
+ if (__t1 >= __t2)
+ __x = __t1 - __t2;
+ else
+ __x = __m - __t2 + __t1;
+ }
+
+ if (__c != 0)
+ {
+ const _Tp __d = __m - __x;
+ if (__d > __c)
+ __x += __c;
+ else
+ __x = __c - __d;
+ }
+ return __x;
+ }
+ };
+
+ // Special case for m == 0 -- use unsigned integer overflow as modulo
+ // operator.
+ template<typename _Tp, _Tp __a, _Tp __c, _Tp __m>
+ struct _Mod<_Tp, __a, __c, __m, true>
+ {
+ static _Tp
+ __calc(_Tp __x)
+ { return __a * __x + __c; }
+ };
+ } // namespace __detail
+
+ /**
+ * Seeds the LCR with integral value @p __x0, adjusted so that the
+ * ring identity is never a member of the convergence set.
+ */
+ template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+ void
+ linear_congruential<_UIntType, __a, __c, __m>::
+ seed(unsigned long __x0)
+ {
+ if ((__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0)
+ && (__detail::__mod<_UIntType, 1, 0, __m>(__x0) == 0))
+ _M_x = __detail::__mod<_UIntType, 1, 0, __m>(1);
+ else
+ _M_x = __detail::__mod<_UIntType, 1, 0, __m>(__x0);
+ }
+
+ /**
+ * Seeds the LCR engine with a value generated by @p __g.
+ */
+ template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+ template<class _Gen>
+ void
+ linear_congruential<_UIntType, __a, __c, __m>::
+ seed(_Gen& __g, false_type)
+ {
+ _UIntType __x0 = __g();
+ if ((__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0)
+ && (__detail::__mod<_UIntType, 1, 0, __m>(__x0) == 0))
+ _M_x = __detail::__mod<_UIntType, 1, 0, __m>(1);
+ else
+ _M_x = __detail::__mod<_UIntType, 1, 0, __m>(__x0);
+ }
+
+ /**
+ * Gets the next generated value in sequence.
+ */
+ template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+ typename linear_congruential<_UIntType, __a, __c, __m>::result_type
+ linear_congruential<_UIntType, __a, __c, __m>::
+ operator()()
+ {
+ _M_x = __detail::__mod<_UIntType, __a, __c, __m>(_M_x);
+ return _M_x;
+ }
+
+ template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const linear_congruential<_UIntType, __a, __c, __m>& __lcr)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
+ __os.fill(__os.widen(' '));
+
+ __os << __lcr._M_x;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ linear_congruential<_UIntType, __a, __c, __m>& __lcr)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec);
+
+ __is >> __lcr._M_x;
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<class _UIntType, int __w, int __n, int __m, int __r,
+ _UIntType __a, int __u, int __s,
+ _UIntType __b, int __t, _UIntType __c, int __l>
+ void
+ mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
+ __b, __t, __c, __l>::
+ seed(unsigned long __value)
+ {
+ _M_x[0] = __detail::__mod<_UIntType, 1, 0,
+ __detail::_Shift<_UIntType, __w>::__value>(__value);
+
+ for (int __i = 1; __i < state_size; ++__i)
+ {
+ _UIntType __x = _M_x[__i - 1];
+ __x ^= __x >> (__w - 2);
+ __x *= 1812433253ul;
+ __x += __i;
+ _M_x[__i] = __detail::__mod<_UIntType, 1, 0,
+ __detail::_Shift<_UIntType, __w>::__value>(__x);
+ }
+ _M_p = state_size;
+ }
+
+ template<class _UIntType, int __w, int __n, int __m, int __r,
+ _UIntType __a, int __u, int __s,
+ _UIntType __b, int __t, _UIntType __c, int __l>
+ template<class _Gen>
+ void
+ mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
+ __b, __t, __c, __l>::
+ seed(_Gen& __gen, false_type)
+ {
+ for (int __i = 0; __i < state_size; ++__i)
+ _M_x[__i] = __detail::__mod<_UIntType, 1, 0,
+ __detail::_Shift<_UIntType, __w>::__value>(__gen());
+ _M_p = state_size;
+ }
+
+ template<class _UIntType, int __w, int __n, int __m, int __r,
+ _UIntType __a, int __u, int __s,
+ _UIntType __b, int __t, _UIntType __c, int __l>
+ typename
+ mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
+ __b, __t, __c, __l>::result_type
+ mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
+ __b, __t, __c, __l>::
+ operator()()
+ {
+ // Reload the vector - cost is O(n) amortized over n calls.
+ if (_M_p >= state_size)
+ {
+ const _UIntType __upper_mask = (~_UIntType()) << __r;
+ const _UIntType __lower_mask = ~__upper_mask;
+
+ for (int __k = 0; __k < (__n - __m); ++__k)
+ {
+ _UIntType __y = ((_M_x[__k] & __upper_mask)
+ | (_M_x[__k + 1] & __lower_mask));
+ _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
+ ^ ((__y & 0x01) ? __a : 0));
+ }
+
+ for (int __k = (__n - __m); __k < (__n - 1); ++__k)
+ {
+ _UIntType __y = ((_M_x[__k] & __upper_mask)
+ | (_M_x[__k + 1] & __lower_mask));
+ _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
+ ^ ((__y & 0x01) ? __a : 0));
+ }
+
+ _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
+ | (_M_x[0] & __lower_mask));
+ _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
+ ^ ((__y & 0x01) ? __a : 0));
+ _M_p = 0;
+ }
+
+ // Calculate o(x(i)).
+ result_type __z = _M_x[_M_p++];
+ __z ^= (__z >> __u);
+ __z ^= (__z << __s) & __b;
+ __z ^= (__z << __t) & __c;
+ __z ^= (__z >> __l);
+
+ return __z;
+ }
+
+ template<class _UIntType, int __w, int __n, int __m, int __r,
+ _UIntType __a, int __u, int __s, _UIntType __b, int __t,
+ _UIntType __c, int __l,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const mersenne_twister<_UIntType, __w, __n, __m,
+ __r, __a, __u, __s, __b, __t, __c, __l>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
+ __os.fill(__space);
+
+ for (int __i = 0; __i < __n - 1; ++__i)
+ __os << __x._M_x[__i] << __space;
+ __os << __x._M_x[__n - 1];
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<class _UIntType, int __w, int __n, int __m, int __r,
+ _UIntType __a, int __u, int __s, _UIntType __b, int __t,
+ _UIntType __c, int __l,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ mersenne_twister<_UIntType, __w, __n, __m,
+ __r, __a, __u, __s, __b, __t, __c, __l>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ for (int __i = 0; __i < __n; ++__i)
+ __is >> __x._M_x[__i];
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _IntType, _IntType __m, int __s, int __r>
+ void
+ subtract_with_carry<_IntType, __m, __s, __r>::
+ seed(unsigned long __value)
+ {
+ if (__value == 0)
+ __value = 19780503;
+
+ std::_GLIBCXX_TR1 linear_congruential<unsigned long, 40014, 0, 2147483563>
+ __lcg(__value);
+
+ for (int __i = 0; __i < long_lag; ++__i)
+ _M_x[__i] = __detail::__mod<_UIntType, 1, 0, modulus>(__lcg());
+
+ _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
+ _M_p = 0;
+ }
+
+ template<typename _IntType, _IntType __m, int __s, int __r>
+ template<class _Gen>
+ void
+ subtract_with_carry<_IntType, __m, __s, __r>::
+ seed(_Gen& __gen, false_type)
+ {
+ const int __n = (std::numeric_limits<_UIntType>::digits + 31) / 32;
+
+ for (int __i = 0; __i < long_lag; ++__i)
+ {
+ _UIntType __tmp = 0;
+ _UIntType __factor = 1;
+ for (int __j = 0; __j < __n; ++__j)
+ {
+ __tmp += __detail::__mod<__detail::_UInt32Type, 1, 0, 0>
+ (__gen()) * __factor;
+ __factor *= __detail::_Shift<_UIntType, 32>::__value;
+ }
+ _M_x[__i] = __detail::__mod<_UIntType, 1, 0, modulus>(__tmp);
+ }
+ _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
+ _M_p = 0;
+ }
+
+ template<typename _IntType, _IntType __m, int __s, int __r>
+ typename subtract_with_carry<_IntType, __m, __s, __r>::result_type
+ subtract_with_carry<_IntType, __m, __s, __r>::
+ operator()()
+ {
+ // Derive short lag index from current index.
+ int __ps = _M_p - short_lag;
+ if (__ps < 0)
+ __ps += long_lag;
+
+ // Calculate new x(i) without overflow or division.
+ // NB: Thanks to the requirements for _IntType, _M_x[_M_p] + _M_carry
+ // cannot overflow.
+ _UIntType __xi;
+ if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
+ {
+ __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
+ _M_carry = 0;
+ }
+ else
+ {
+ __xi = modulus - _M_x[_M_p] - _M_carry + _M_x[__ps];
+ _M_carry = 1;
+ }
+ _M_x[_M_p] = __xi;
+
+ // Adjust current index to loop around in ring buffer.
+ if (++_M_p >= long_lag)
+ _M_p = 0;
+
+ return __xi;
+ }
+
+ template<typename _IntType, _IntType __m, int __s, int __r,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const subtract_with_carry<_IntType, __m, __s, __r>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
+ __os.fill(__space);
+
+ for (int __i = 0; __i < __r; ++__i)
+ __os << __x._M_x[__i] << __space;
+ __os << __x._M_carry;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<typename _IntType, _IntType __m, int __s, int __r,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ subtract_with_carry<_IntType, __m, __s, __r>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ for (int __i = 0; __i < __r; ++__i)
+ __is >> __x._M_x[__i];
+ __is >> __x._M_carry;
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType, int __w, int __s, int __r>
+ void
+ subtract_with_carry_01<_RealType, __w, __s, __r>::
+ _M_initialize_npows()
+ {
+ for (int __j = 0; __j < __n; ++__j)
+#if _GLIBCXX_USE_C99_MATH_TR1
+ _M_npows[__j] = std::_GLIBCXX_TR1 ldexp(_RealType(1), -__w + __j * 32);
+#else
+ _M_npows[__j] = std::pow(_RealType(2), -__w + __j * 32);
+#endif
+ }
+
+ template<typename _RealType, int __w, int __s, int __r>
+ void
+ subtract_with_carry_01<_RealType, __w, __s, __r>::
+ seed(unsigned long __value)
+ {
+ if (__value == 0)
+ __value = 19780503;
+
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 512. Seeding subtract_with_carry_01 from a single unsigned long.
+ std::_GLIBCXX_TR1 linear_congruential<unsigned long, 40014, 0, 2147483563>
+ __lcg(__value);
+
+ this->seed(__lcg);
+ }
+
+ template<typename _RealType, int __w, int __s, int __r>
+ template<class _Gen>
+ void
+ subtract_with_carry_01<_RealType, __w, __s, __r>::
+ seed(_Gen& __gen, false_type)
+ {
+ for (int __i = 0; __i < long_lag; ++__i)
+ {
+ for (int __j = 0; __j < __n - 1; ++__j)
+ _M_x[__i][__j] = __detail::__mod<_UInt32Type, 1, 0, 0>(__gen());
+ _M_x[__i][__n - 1] = __detail::__mod<_UInt32Type, 1, 0,
+ __detail::_Shift<_UInt32Type, __w % 32>::__value>(__gen());
+ }
+
+ _M_carry = 1;
+ for (int __j = 0; __j < __n; ++__j)
+ if (_M_x[long_lag - 1][__j] != 0)
+ {
+ _M_carry = 0;
+ break;
+ }
+
+ _M_p = 0;
+ }
+
+ template<typename _RealType, int __w, int __s, int __r>
+ typename subtract_with_carry_01<_RealType, __w, __s, __r>::result_type
+ subtract_with_carry_01<_RealType, __w, __s, __r>::
+ operator()()
+ {
+ // Derive short lag index from current index.
+ int __ps = _M_p - short_lag;
+ if (__ps < 0)
+ __ps += long_lag;
+
+ _UInt32Type __new_carry;
+ for (int __j = 0; __j < __n - 1; ++__j)
+ {
+ if (_M_x[__ps][__j] > _M_x[_M_p][__j]
+ || (_M_x[__ps][__j] == _M_x[_M_p][__j] && _M_carry == 0))
+ __new_carry = 0;
+ else
+ __new_carry = 1;
+
+ _M_x[_M_p][__j] = _M_x[__ps][__j] - _M_x[_M_p][__j] - _M_carry;
+ _M_carry = __new_carry;
+ }
+
+ if (_M_x[__ps][__n - 1] > _M_x[_M_p][__n - 1]
+ || (_M_x[__ps][__n - 1] == _M_x[_M_p][__n - 1] && _M_carry == 0))
+ __new_carry = 0;
+ else
+ __new_carry = 1;
+
+ _M_x[_M_p][__n - 1] = __detail::__mod<_UInt32Type, 1, 0,
+ __detail::_Shift<_UInt32Type, __w % 32>::__value>
+ (_M_x[__ps][__n - 1] - _M_x[_M_p][__n - 1] - _M_carry);
+ _M_carry = __new_carry;
+
+ result_type __ret = 0.0;
+ for (int __j = 0; __j < __n; ++__j)
+ __ret += _M_x[_M_p][__j] * _M_npows[__j];
+
+ // Adjust current index to loop around in ring buffer.
+ if (++_M_p >= long_lag)
+ _M_p = 0;
+
+ return __ret;
+ }
+
+ template<typename _RealType, int __w, int __s, int __r,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const subtract_with_carry_01<_RealType, __w, __s, __r>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
+ __os.fill(__space);
+
+ for (int __i = 0; __i < __r; ++__i)
+ for (int __j = 0; __j < __x.__n; ++__j)
+ __os << __x._M_x[__i][__j] << __space;
+ __os << __x._M_carry;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<typename _RealType, int __w, int __s, int __r,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ subtract_with_carry_01<_RealType, __w, __s, __r>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ for (int __i = 0; __i < __r; ++__i)
+ for (int __j = 0; __j < __x.__n; ++__j)
+ __is >> __x._M_x[__i][__j];
+ __is >> __x._M_carry;
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<class _UniformRandomNumberGenerator, int __p, int __r>
+ typename discard_block<_UniformRandomNumberGenerator,
+ __p, __r>::result_type
+ discard_block<_UniformRandomNumberGenerator, __p, __r>::
+ operator()()
+ {
+ if (_M_n >= used_block)
+ {
+ while (_M_n < block_size)
+ {
+ _M_b();
+ ++_M_n;
+ }
+ _M_n = 0;
+ }
+ ++_M_n;
+ return _M_b();
+ }
+
+ template<class _UniformRandomNumberGenerator, int __p, int __r,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const discard_block<_UniformRandomNumberGenerator,
+ __p, __r>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::dec | __ios_base::fixed
+ | __ios_base::left);
+ __os.fill(__space);
+
+ __os << __x._M_b << __space << __x._M_n;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<class _UniformRandomNumberGenerator, int __p, int __r,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ discard_block<_UniformRandomNumberGenerator, __p, __r>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ __is >> __x._M_b >> __x._M_n;
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<class _UniformRandomNumberGenerator1, int __s1,
+ class _UniformRandomNumberGenerator2, int __s2>
+ void
+ xor_combine<_UniformRandomNumberGenerator1, __s1,
+ _UniformRandomNumberGenerator2, __s2>::
+ _M_initialize_max()
+ {
+ const int __w = std::numeric_limits<result_type>::digits;
+
+ const result_type __m1 =
+ std::min(result_type(_M_b1.max() - _M_b1.min()),
+ __detail::_Shift<result_type, __w - __s1>::__value - 1);
+
+ const result_type __m2 =
+ std::min(result_type(_M_b2.max() - _M_b2.min()),
+ __detail::_Shift<result_type, __w - __s2>::__value - 1);
+
+ // NB: In TR1 s1 is not required to be >= s2.
+ if (__s1 < __s2)
+ _M_max = _M_initialize_max_aux(__m2, __m1, __s2 - __s1) << __s1;
+ else
+ _M_max = _M_initialize_max_aux(__m1, __m2, __s1 - __s2) << __s2;
+ }
+
+ template<class _UniformRandomNumberGenerator1, int __s1,
+ class _UniformRandomNumberGenerator2, int __s2>
+ typename xor_combine<_UniformRandomNumberGenerator1, __s1,
+ _UniformRandomNumberGenerator2, __s2>::result_type
+ xor_combine<_UniformRandomNumberGenerator1, __s1,
+ _UniformRandomNumberGenerator2, __s2>::
+ _M_initialize_max_aux(result_type __a, result_type __b, int __d)
+ {
+ const result_type __two2d = result_type(1) << __d;
+ const result_type __c = __a * __two2d;
+
+ if (__a == 0 || __b < __two2d)
+ return __c + __b;
+
+ const result_type __t = std::max(__c, __b);
+ const result_type __u = std::min(__c, __b);
+
+ result_type __ub = __u;
+ result_type __p;
+ for (__p = 0; __ub != 1; __ub >>= 1)
+ ++__p;
+
+ const result_type __two2p = result_type(1) << __p;
+ const result_type __k = __t / __two2p;
+
+ if (__k & 1)
+ return (__k + 1) * __two2p - 1;
+
+ if (__c >= __b)
+ return (__k + 1) * __two2p + _M_initialize_max_aux((__t % __two2p)
+ / __two2d,
+ __u % __two2p, __d);
+ else
+ return (__k + 1) * __two2p + _M_initialize_max_aux((__u % __two2p)
+ / __two2d,
+ __t % __two2p, __d);
+ }
+
+ template<class _UniformRandomNumberGenerator1, int __s1,
+ class _UniformRandomNumberGenerator2, int __s2,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const xor_combine<_UniformRandomNumberGenerator1, __s1,
+ _UniformRandomNumberGenerator2, __s2>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
+ __os.fill(__space);
+
+ __os << __x.base1() << __space << __x.base2();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<class _UniformRandomNumberGenerator1, int __s1,
+ class _UniformRandomNumberGenerator2, int __s2,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ xor_combine<_UniformRandomNumberGenerator1, __s1,
+ _UniformRandomNumberGenerator2, __s2>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::skipws);
+
+ __is >> __x._M_b1 >> __x._M_b2;
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _IntType>
+ template<typename _UniformRandomNumberGenerator>
+ typename uniform_int<_IntType>::result_type
+ uniform_int<_IntType>::
+ _M_call(_UniformRandomNumberGenerator& __urng,
+ result_type __min, result_type __max, true_type)
+ {
+ // XXX Must be fixed to work well for *arbitrary* __urng.max(),
+ // __urng.min(), __max, __min. Currently works fine only in the
+ // most common case __urng.max() - __urng.min() >= __max - __min,
+ // with __urng.max() > __urng.min() >= 0.
+ typedef typename __gnu_cxx::__add_unsigned<typename
+ _UniformRandomNumberGenerator::result_type>::__type __urntype;
+ typedef typename __gnu_cxx::__add_unsigned<result_type>::__type
+ __utype;
+ typedef typename __gnu_cxx::__conditional_type<(sizeof(__urntype)
+ > sizeof(__utype)),
+ __urntype, __utype>::__type __uctype;
+
+ result_type __ret;
+
+ const __urntype __urnmin = __urng.min();
+ const __urntype __urnmax = __urng.max();
+ const __urntype __urnrange = __urnmax - __urnmin;
+ const __uctype __urange = __max - __min;
+ const __uctype __udenom = (__urnrange <= __urange
+ ? 1 : __urnrange / (__urange + 1));
+ do
+ __ret = (__urntype(__urng()) - __urnmin) / __udenom;
+ while (__ret > __max - __min);
+
+ return __ret + __min;
+ }
+
+ template<typename _IntType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const uniform_int<_IntType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+
+ __os << __x.min() << __space << __x.max();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ return __os;
+ }
+
+ template<typename _IntType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ uniform_int<_IntType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ __is >> __x._M_min >> __x._M_max;
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const bernoulli_distribution& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__os.widen(' '));
+ __os.precision(__gnu_cxx::__numeric_traits<double>::__max_digits10);
+
+ __os << __x.p();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+
+ template<typename _IntType, typename _RealType>
+ template<class _UniformRandomNumberGenerator>
+ typename geometric_distribution<_IntType, _RealType>::result_type
+ geometric_distribution<_IntType, _RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng)
+ {
+ // About the epsilon thing see this thread:
+ // http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00971.html
+ const _RealType __naf =
+ (1 - std::numeric_limits<_RealType>::epsilon()) / 2;
+ // The largest _RealType convertible to _IntType.
+ const _RealType __thr =
+ std::numeric_limits<_IntType>::max() + __naf;
+
+ _RealType __cand;
+ do
+ __cand = std::ceil(std::log(__urng()) / _M_log_p);
+ while (__cand >= __thr);
+
+ return result_type(__cand + __naf);
+ }
+
+ template<typename _IntType, typename _RealType,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const geometric_distribution<_IntType, _RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__os.widen(' '));
+ __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
+
+ __os << __x.p();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+
+ template<typename _IntType, typename _RealType>
+ void
+ poisson_distribution<_IntType, _RealType>::
+ _M_initialize()
+ {
+#if _GLIBCXX_USE_C99_MATH_TR1
+ if (_M_mean >= 12)
+ {
+ const _RealType __m = std::floor(_M_mean);
+ _M_lm_thr = std::log(_M_mean);
+ _M_lfm = std::_GLIBCXX_TR1 lgamma(__m + 1);
+ _M_sm = std::sqrt(__m);
+
+ const _RealType __pi_4 = 0.7853981633974483096156608458198757L;
+ const _RealType __dx = std::sqrt(2 * __m * std::log(32 * __m
+ / __pi_4));
+ _M_d = std::_GLIBCXX_TR1 round(std::max(_RealType(6),
+ std::min(__m, __dx)));
+ const _RealType __cx = 2 * __m + _M_d;
+ _M_scx = std::sqrt(__cx / 2);
+ _M_1cx = 1 / __cx;
+
+ _M_c2b = std::sqrt(__pi_4 * __cx) * std::exp(_M_1cx);
+ _M_cb = 2 * __cx * std::exp(-_M_d * _M_1cx * (1 + _M_d / 2)) / _M_d;
+ }
+ else
+#endif
+ _M_lm_thr = std::exp(-_M_mean);
+ }
+
+ /**
+ * A rejection algorithm when mean >= 12 and a simple method based
+ * upon the multiplication of uniform random variates otherwise.
+ * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1
+ * is defined.
+ *
+ * Reference:
+ * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag,
+ * New York, 1986, Ch. X, Sects. 3.3 & 3.4 (+ Errata!).
+ */
+ template<typename _IntType, typename _RealType>
+ template<class _UniformRandomNumberGenerator>
+ typename poisson_distribution<_IntType, _RealType>::result_type
+ poisson_distribution<_IntType, _RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng)
+ {
+#if _GLIBCXX_USE_C99_MATH_TR1
+ if (_M_mean >= 12)
+ {
+ _RealType __x;
+
+ // See comments above...
+ const _RealType __naf =
+ (1 - std::numeric_limits<_RealType>::epsilon()) / 2;
+ const _RealType __thr =
+ std::numeric_limits<_IntType>::max() + __naf;
+
+ const _RealType __m = std::floor(_M_mean);
+ // sqrt(pi / 2)
+ const _RealType __spi_2 = 1.2533141373155002512078826424055226L;
+ const _RealType __c1 = _M_sm * __spi_2;
+ const _RealType __c2 = _M_c2b + __c1;
+ const _RealType __c3 = __c2 + 1;
+ const _RealType __c4 = __c3 + 1;
+ // e^(1 / 78)
+ const _RealType __e178 = 1.0129030479320018583185514777512983L;
+ const _RealType __c5 = __c4 + __e178;
+ const _RealType __c = _M_cb + __c5;
+ const _RealType __2cx = 2 * (2 * __m + _M_d);
+
+ bool __reject = true;
+ do
+ {
+ const _RealType __u = __c * __urng();
+ const _RealType __e = -std::log(__urng());
+
+ _RealType __w = 0.0;
+
+ if (__u <= __c1)
+ {
+ const _RealType __n = _M_nd(__urng);
+ const _RealType __y = -std::abs(__n) * _M_sm - 1;
+ __x = std::floor(__y);
+ __w = -__n * __n / 2;
+ if (__x < -__m)
+ continue;
+ }
+ else if (__u <= __c2)
+ {
+ const _RealType __n = _M_nd(__urng);
+ const _RealType __y = 1 + std::abs(__n) * _M_scx;
+ __x = std::ceil(__y);
+ __w = __y * (2 - __y) * _M_1cx;
+ if (__x > _M_d)
+ continue;
+ }
+ else if (__u <= __c3)
+ // NB: This case not in the book, nor in the Errata,
+ // but should be ok...
+ __x = -1;
+ else if (__u <= __c4)
+ __x = 0;
+ else if (__u <= __c5)
+ __x = 1;
+ else
+ {
+ const _RealType __v = -std::log(__urng());
+ const _RealType __y = _M_d + __v * __2cx / _M_d;
+ __x = std::ceil(__y);
+ __w = -_M_d * _M_1cx * (1 + __y / 2);
+ }
+
+ __reject = (__w - __e - __x * _M_lm_thr
+ > _M_lfm - std::_GLIBCXX_TR1 lgamma(__x + __m + 1));
+
+ __reject |= __x + __m >= __thr;
+
+ } while (__reject);
+
+ return result_type(__x + __m + __naf);
+ }
+ else
+#endif
+ {
+ _IntType __x = 0;
+ _RealType __prod = 1.0;
+
+ do
+ {
+ __prod *= __urng();
+ __x += 1;
+ }
+ while (__prod > _M_lm_thr);
+
+ return __x - 1;
+ }
+ }
+
+ template<typename _IntType, typename _RealType,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const poisson_distribution<_IntType, _RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
+
+ __os << __x.mean() << __space << __x._M_nd;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _IntType, typename _RealType,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ poisson_distribution<_IntType, _RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::skipws);
+
+ __is >> __x._M_mean >> __x._M_nd;
+ __x._M_initialize();
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _IntType, typename _RealType>
+ void
+ binomial_distribution<_IntType, _RealType>::
+ _M_initialize()
+ {
+ const _RealType __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
+
+ _M_easy = true;
+
+#if _GLIBCXX_USE_C99_MATH_TR1
+ if (_M_t * __p12 >= 8)
+ {
+ _M_easy = false;
+ const _RealType __np = std::floor(_M_t * __p12);
+ const _RealType __pa = __np / _M_t;
+ const _RealType __1p = 1 - __pa;
+
+ const _RealType __pi_4 = 0.7853981633974483096156608458198757L;
+ const _RealType __d1x =
+ std::sqrt(__np * __1p * std::log(32 * __np
+ / (81 * __pi_4 * __1p)));
+ _M_d1 = std::_GLIBCXX_TR1 round(std::max(_RealType(1), __d1x));
+ const _RealType __d2x =
+ std::sqrt(__np * __1p * std::log(32 * _M_t * __1p
+ / (__pi_4 * __pa)));
+ _M_d2 = std::_GLIBCXX_TR1 round(std::max(_RealType(1), __d2x));
+
+ // sqrt(pi / 2)
+ const _RealType __spi_2 = 1.2533141373155002512078826424055226L;
+ _M_s1 = std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
+ _M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
+ _M_c = 2 * _M_d1 / __np;
+ _M_a1 = std::exp(_M_c) * _M_s1 * __spi_2;
+ const _RealType __a12 = _M_a1 + _M_s2 * __spi_2;
+ const _RealType __s1s = _M_s1 * _M_s1;
+ _M_a123 = __a12 + (std::exp(_M_d1 / (_M_t * __1p))
+ * 2 * __s1s / _M_d1
+ * std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
+ const _RealType __s2s = _M_s2 * _M_s2;
+ _M_s = (_M_a123 + 2 * __s2s / _M_d2
+ * std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
+ _M_lf = (std::_GLIBCXX_TR1 lgamma(__np + 1)
+ + std::_GLIBCXX_TR1 lgamma(_M_t - __np + 1));
+ _M_lp1p = std::log(__pa / __1p);
+
+ _M_q = -std::log(1 - (__p12 - __pa) / __1p);
+ }
+ else
+#endif
+ _M_q = -std::log(1 - __p12);
+ }
+
+ template<typename _IntType, typename _RealType>
+ template<class _UniformRandomNumberGenerator>
+ typename binomial_distribution<_IntType, _RealType>::result_type
+ binomial_distribution<_IntType, _RealType>::
+ _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t)
+ {
+ _IntType __x = 0;
+ _RealType __sum = 0;
+
+ do
+ {
+ const _RealType __e = -std::log(__urng());
+ __sum += __e / (__t - __x);
+ __x += 1;
+ }
+ while (__sum <= _M_q);
+
+ return __x - 1;
+ }
+
+ /**
+ * A rejection algorithm when t * p >= 8 and a simple waiting time
+ * method - the second in the referenced book - otherwise.
+ * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1
+ * is defined.
+ *
+ * Reference:
+ * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag,
+ * New York, 1986, Ch. X, Sect. 4 (+ Errata!).
+ */
+ template<typename _IntType, typename _RealType>
+ template<class _UniformRandomNumberGenerator>
+ typename binomial_distribution<_IntType, _RealType>::result_type
+ binomial_distribution<_IntType, _RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng)
+ {
+ result_type __ret;
+ const _RealType __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
+
+#if _GLIBCXX_USE_C99_MATH_TR1
+ if (!_M_easy)
+ {
+ _RealType __x;
+
+ // See comments above...
+ const _RealType __naf =
+ (1 - std::numeric_limits<_RealType>::epsilon()) / 2;
+ const _RealType __thr =
+ std::numeric_limits<_IntType>::max() + __naf;
+
+ const _RealType __np = std::floor(_M_t * __p12);
+ const _RealType __pa = __np / _M_t;
+
+ // sqrt(pi / 2)
+ const _RealType __spi_2 = 1.2533141373155002512078826424055226L;
+ const _RealType __a1 = _M_a1;
+ const _RealType __a12 = __a1 + _M_s2 * __spi_2;
+ const _RealType __a123 = _M_a123;
+ const _RealType __s1s = _M_s1 * _M_s1;
+ const _RealType __s2s = _M_s2 * _M_s2;
+
+ bool __reject;
+ do
+ {
+ const _RealType __u = _M_s * __urng();
+
+ _RealType __v;
+
+ if (__u <= __a1)
+ {
+ const _RealType __n = _M_nd(__urng);
+ const _RealType __y = _M_s1 * std::abs(__n);
+ __reject = __y >= _M_d1;
+ if (!__reject)
+ {
+ const _RealType __e = -std::log(__urng());
+ __x = std::floor(__y);
+ __v = -__e - __n * __n / 2 + _M_c;
+ }
+ }
+ else if (__u <= __a12)
+ {
+ const _RealType __n = _M_nd(__urng);
+ const _RealType __y = _M_s2 * std::abs(__n);
+ __reject = __y >= _M_d2;
+ if (!__reject)
+ {
+ const _RealType __e = -std::log(__urng());
+ __x = std::floor(-__y);
+ __v = -__e - __n * __n / 2;
+ }
+ }
+ else if (__u <= __a123)
+ {
+ const _RealType __e1 = -std::log(__urng());
+ const _RealType __e2 = -std::log(__urng());
+
+ const _RealType __y = _M_d1 + 2 * __s1s * __e1 / _M_d1;
+ __x = std::floor(__y);
+ __v = (-__e2 + _M_d1 * (1 / (_M_t - __np)
+ -__y / (2 * __s1s)));
+ __reject = false;
+ }
+ else
+ {
+ const _RealType __e1 = -std::log(__urng());
+ const _RealType __e2 = -std::log(__urng());
+
+ const _RealType __y = _M_d2 + 2 * __s2s * __e1 / _M_d2;
+ __x = std::floor(-__y);
+ __v = -__e2 - _M_d2 * __y / (2 * __s2s);
+ __reject = false;
+ }
+
+ __reject = __reject || __x < -__np || __x > _M_t - __np;
+ if (!__reject)
+ {
+ const _RealType __lfx =
+ std::_GLIBCXX_TR1 lgamma(__np + __x + 1)
+ + std::_GLIBCXX_TR1 lgamma(_M_t - (__np + __x) + 1);
+ __reject = __v > _M_lf - __lfx + __x * _M_lp1p;
+ }
+
+ __reject |= __x + __np >= __thr;
+ }
+ while (__reject);
+
+ __x += __np + __naf;
+
+ const _IntType __z = _M_waiting(__urng, _M_t - _IntType(__x));
+ __ret = _IntType(__x) + __z;
+ }
+ else
+#endif
+ __ret = _M_waiting(__urng, _M_t);
+
+ if (__p12 != _M_p)
+ __ret = _M_t - __ret;
+ return __ret;
+ }
+
+ template<typename _IntType, typename _RealType,
+ typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const binomial_distribution<_IntType, _RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
+
+ __os << __x.t() << __space << __x.p()
+ << __space << __x._M_nd;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _IntType, typename _RealType,
+ typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ binomial_distribution<_IntType, _RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ __is >> __x._M_t >> __x._M_p >> __x._M_nd;
+ __x._M_initialize();
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const uniform_real<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
+
+ __os << __x.min() << __space << __x.max();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ uniform_real<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::skipws);
+
+ __is >> __x._M_min >> __x._M_max;
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const exponential_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__os.widen(' '));
+ __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
+
+ __os << __x.lambda();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+
+ /**
+ * Polar method due to Marsaglia.
+ *
+ * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag,
+ * New York, 1986, Ch. V, Sect. 4.4.
+ */
+ template<typename _RealType>
+ template<class _UniformRandomNumberGenerator>
+ typename normal_distribution<_RealType>::result_type
+ normal_distribution<_RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng)
+ {
+ result_type __ret;
+
+ if (_M_saved_available)
+ {
+ _M_saved_available = false;
+ __ret = _M_saved;
+ }
+ else
+ {
+ result_type __x, __y, __r2;
+ do
+ {
+ __x = result_type(2.0) * __urng() - 1.0;
+ __y = result_type(2.0) * __urng() - 1.0;
+ __r2 = __x * __x + __y * __y;
+ }
+ while (__r2 > 1.0 || __r2 == 0.0);
+
+ const result_type __mult = std::sqrt(-2 * std::log(__r2) / __r2);
+ _M_saved = __x * __mult;
+ _M_saved_available = true;
+ __ret = __y * __mult;
+ }
+
+ __ret = __ret * _M_sigma + _M_mean;
+ return __ret;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const normal_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ const _CharT __space = __os.widen(' ');
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__space);
+ __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
+
+ __os << __x._M_saved_available << __space
+ << __x.mean() << __space
+ << __x.sigma();
+ if (__x._M_saved_available)
+ __os << __space << __x._M_saved;
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ normal_distribution<_RealType>& __x)
+ {
+ typedef std::basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __is.flags();
+ __is.flags(__ios_base::dec | __ios_base::skipws);
+
+ __is >> __x._M_saved_available >> __x._M_mean
+ >> __x._M_sigma;
+ if (__x._M_saved_available)
+ __is >> __x._M_saved;
+
+ __is.flags(__flags);
+ return __is;
+ }
+
+
+ template<typename _RealType>
+ void
+ gamma_distribution<_RealType>::
+ _M_initialize()
+ {
+ if (_M_alpha >= 1)
+ _M_l_d = std::sqrt(2 * _M_alpha - 1);
+ else
+ _M_l_d = (std::pow(_M_alpha, _M_alpha / (1 - _M_alpha))
+ * (1 - _M_alpha));
+ }
+
+ /**
+ * Cheng's rejection algorithm GB for alpha >= 1 and a modification
+ * of Vaduva's rejection from Weibull algorithm due to Devroye for
+ * alpha < 1.
+ *
+ * References:
+ * Cheng, R. C. "The Generation of Gamma Random Variables with Non-integral
+ * Shape Parameter." Applied Statistics, 26, 71-75, 1977.
+ *
+ * Vaduva, I. "Computer Generation of Gamma Gandom Variables by Rejection
+ * and Composition Procedures." Math. Operationsforschung and Statistik,
+ * Series in Statistics, 8, 545-576, 1977.
+ *
+ * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag,
+ * New York, 1986, Ch. IX, Sect. 3.4 (+ Errata!).
+ */
+ template<typename _RealType>
+ template<class _UniformRandomNumberGenerator>
+ typename gamma_distribution<_RealType>::result_type
+ gamma_distribution<_RealType>::
+ operator()(_UniformRandomNumberGenerator& __urng)
+ {
+ result_type __x;
+
+ bool __reject;
+ if (_M_alpha >= 1)
+ {
+ // alpha - log(4)
+ const result_type __b = _M_alpha
+ - result_type(1.3862943611198906188344642429163531L);
+ const result_type __c = _M_alpha + _M_l_d;
+ const result_type __1l = 1 / _M_l_d;
+
+ // 1 + log(9 / 2)
+ const result_type __k = 2.5040773967762740733732583523868748L;
+
+ do
+ {
+ const result_type __u = __urng();
+ const result_type __v = __urng();
+
+ const result_type __y = __1l * std::log(__v / (1 - __v));
+ __x = _M_alpha * std::exp(__y);
+
+ const result_type __z = __u * __v * __v;
+ const result_type __r = __b + __c * __y - __x;
+
+ __reject = __r < result_type(4.5) * __z - __k;
+ if (__reject)
+ __reject = __r < std::log(__z);
+ }
+ while (__reject);
+ }
+ else
+ {
+ const result_type __c = 1 / _M_alpha;
+
+ do
+ {
+ const result_type __z = -std::log(__urng());
+ const result_type __e = -std::log(__urng());
+
+ __x = std::pow(__z, __c);
+
+ __reject = __z + __e < _M_l_d + __x;
+ }
+ while (__reject);
+ }
+
+ return __x;
+ }
+
+ template<typename _RealType, typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const gamma_distribution<_RealType>& __x)
+ {
+ typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename __ostream_type::ios_base __ios_base;
+
+ const typename __ios_base::fmtflags __flags = __os.flags();
+ const _CharT __fill = __os.fill();
+ const std::streamsize __precision = __os.precision();
+ __os.flags(__ios_base::scientific | __ios_base::left);
+ __os.fill(__os.widen(' '));
+ __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
+
+ __os << __x.alpha();
+
+ __os.flags(__flags);
+ __os.fill(__fill);
+ __os.precision(__precision);
+ return __os;
+ }
+
+}
+}
diff --git a/libstdc++-v3/include/tr1_impl/random b/libstdc++-v3/include/tr1_impl/random
index 49ac5980854..e69de29bb2d 100644
--- a/libstdc++-v3/include/tr1_impl/random
+++ b/libstdc++-v3/include/tr1_impl/random
@@ -1,2412 +0,0 @@
-// random number generation -*- C++ -*-
-
-// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library. This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING. If not, write to the Free
-// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
-
-// As a special exception, you may use this file as part of a free software
-// library without restriction. Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License. This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
-
-/**
- * @file tr1_impl/random
- * This is an internal header file, included by other library headers.
- * You should not attempt to use it directly.
- */
-
-namespace std
-{
-_GLIBCXX_BEGIN_NAMESPACE_TR1
-
- // [5.1] Random number generation
-
- /**
- * @defgroup tr1_random Random Number Generation
- * @ingroup numerics
- * A facility for generating random numbers on selected distributions.
- * @{
- */
-
- /*
- * Implementation-space details.
- */
- namespace __detail
- {
- template<typename _UIntType, int __w,
- bool = __w < std::numeric_limits<_UIntType>::digits>
- struct _Shift
- { static const _UIntType __value = 0; };
-
- template<typename _UIntType, int __w>
- struct _Shift<_UIntType, __w, true>
- { static const _UIntType __value = _UIntType(1) << __w; };
-
- template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool>
- struct _Mod;
-
- // Dispatch based on modulus value to prevent divide-by-zero compile-time
- // errors when m == 0.
- template<typename _Tp, _Tp __a, _Tp __c, _Tp __m>
- inline _Tp
- __mod(_Tp __x)
- { return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); }
-
- typedef __gnu_cxx::__conditional_type<(sizeof(unsigned) == 4),
- unsigned, unsigned long>::__type _UInt32Type;
-
- /*
- * An adaptor class for converting the output of any Generator into
- * the input for a specific Distribution.
- */
- template<typename _Engine, typename _Distribution>
- struct _Adaptor
- {
- typedef typename remove_reference<_Engine>::type _BEngine;
- typedef typename _BEngine::result_type _Engine_result_type;
- typedef typename _Distribution::input_type result_type;
-
- public:
- _Adaptor(const _Engine& __g)
- : _M_g(__g) { }
-
- result_type
- min() const
- {
- result_type __return_value;
- if (is_integral<_Engine_result_type>::value
- && is_integral<result_type>::value)
- __return_value = _M_g.min();
- else
- __return_value = result_type(0);
- return __return_value;
- }
-
- result_type
- max() const
- {
- result_type __return_value;
- if (is_integral<_Engine_result_type>::value
- && is_integral<result_type>::value)
- __return_value = _M_g.max();
- else if (!is_integral<result_type>::value)
- __return_value = result_type(1);
- else
- __return_value = std::numeric_limits<result_type>::max() - 1;
- return __return_value;
- }
-
- /*
- * Converts a value generated by the adapted random number generator
- * into a value in the input domain for the dependent random number
- * distribution.
- *
- * Because the type traits are compile time constants only the
- * appropriate clause of the if statements will actually be emitted
- * by the compiler.
- */
- result_type
- operator()()
- {
- result_type __return_value;
- if (is_integral<_Engine_result_type>::value
- && is_integral<result_type>::value)
- __return_value = _M_g();
- else if (!is_integral<_Engine_result_type>::value
- && !is_integral<result_type>::value)
- __return_value = result_type(_M_g() - _M_g.min())
- / result_type(_M_g.max() - _M_g.min());
- else if (is_integral<_Engine_result_type>::value
- && !is_integral<result_type>::value)
- __return_value = result_type(_M_g() - _M_g.min())
- / result_type(_M_g.max() - _M_g.min() + result_type(1));
- else
- __return_value = (((_M_g() - _M_g.min())
- / (_M_g.max() - _M_g.min()))
- * std::numeric_limits<result_type>::max());
- return __return_value;
- }
-
- private:
- _Engine _M_g;
- };
-
- // Specialization for _Engine*.
- template<typename _Engine, typename _Distribution>
- struct _Adaptor<_Engine*, _Distribution>
- {
- typedef typename _Engine::result_type _Engine_result_type;
- typedef typename _Distribution::input_type result_type;
-
- public:
- _Adaptor(_Engine* __g)
- : _M_g(__g) { }
-
- result_type
- min() const
- {
- result_type __return_value;
- if (is_integral<_Engine_result_type>::value
- && is_integral<result_type>::value)
- __return_value = _M_g->min();
- else
- __return_value = result_type(0);
- return __return_value;
- }
-
- result_type
- max() const
- {
- result_type __return_value;
- if (is_integral<_Engine_result_type>::value
- && is_integral<result_type>::value)
- __return_value = _M_g->max();
- else if (!is_integral<result_type>::value)
- __return_value = result_type(1);
- else
- __return_value = std::numeric_limits<result_type>::max() - 1;
- return __return_value;
- }
-
- result_type
- operator()()
- {
- result_type __return_value;
- if (is_integral<_Engine_result_type>::value
- && is_integral<result_type>::value)
- __return_value = (*_M_g)();
- else if (!is_integral<_Engine_result_type>::value
- && !is_integral<result_type>::value)
- __return_value = result_type((*_M_g)() - _M_g->min())
- / result_type(_M_g->max() - _M_g->min());
- else if (is_integral<_Engine_result_type>::value
- && !is_integral<result_type>::value)
- __return_value = result_type((*_M_g)() - _M_g->min())
- / result_type(_M_g->max() - _M_g->min() + result_type(1));
- else
- __return_value = ((((*_M_g)() - _M_g->min())
- / (_M_g->max() - _M_g->min()))
- * std::numeric_limits<result_type>::max());
- return __return_value;
- }
-
- private:
- _Engine* _M_g;
- };
- } // namespace __detail
-
- /**
- * Produces random numbers on a given distribution function using a
- * non-uniform random number generation engine.
- *
- * @todo the engine_value_type needs to be studied more carefully.
- */
- template<typename _Engine, typename _Dist>
- class variate_generator
- {
- // Concept requirements.
- __glibcxx_class_requires(_Engine, _CopyConstructibleConcept)
- // __glibcxx_class_requires(_Engine, _EngineConcept)
- // __glibcxx_class_requires(_Dist, _EngineConcept)
-
- public:
- typedef _Engine engine_type;
- typedef __detail::_Adaptor<_Engine, _Dist> engine_value_type;
- typedef _Dist distribution_type;
- typedef typename _Dist::result_type result_type;
-
- // tr1:5.1.1 table 5.1 requirement
- typedef typename __gnu_cxx::__enable_if<
- is_arithmetic<result_type>::value, result_type>::__type _IsValidType;
-
- /**
- * Constructs a variate generator with the uniform random number
- * generator @p __eng for the random distribution @p __dist.
- *
- * @throws Any exceptions which may thrown by the copy constructors of
- * the @p _Engine or @p _Dist objects.
- */
- variate_generator(engine_type __eng, distribution_type __dist)
- : _M_engine(__eng), _M_dist(__dist) { }
-
- /**
- * Gets the next generated value on the distribution.
- */
- result_type
- operator()()
- { return _M_dist(_M_engine); }
-
- /**
- * WTF?
- */
- template<typename _Tp>
- result_type
- operator()(_Tp __value)
- { return _M_dist(_M_engine, __value); }
-
- /**
- * Gets a reference to the underlying uniform random number generator
- * object.
- */
- engine_value_type&
- engine()
- { return _M_engine; }
-
- /**
- * Gets a const reference to the underlying uniform random number
- * generator object.
- */
- const engine_value_type&
- engine() const
- { return _M_engine; }
-
- /**
- * Gets a reference to the underlying random distribution.
- */
- distribution_type&
- distribution()
- { return _M_dist; }
-
- /**
- * Gets a const reference to the underlying random distribution.
- */
- const distribution_type&
- distribution() const
- { return _M_dist; }
-
- /**
- * Gets the closed lower bound of the distribution interval.
- */
- result_type
- min() const
- { return this->distribution().min(); }
-
- /**
- * Gets the closed upper bound of the distribution interval.
- */
- result_type
- max() const
- { return this->distribution().max(); }
-
- private:
- engine_value_type _M_engine;
- distribution_type _M_dist;
- };
-
-
- /**
- * @defgroup tr1_random_generators Random Number Generators
- * @ingroup tr1_random
- *
- * These classes define objects which provide random or pseudorandom
- * numbers, either from a discrete or a continuous interval. The
- * random number generator supplied as a part of this library are
- * all uniform random number generators which provide a sequence of
- * random number uniformly distributed over their range.
- *
- * A number generator is a function object with an operator() that
- * takes zero arguments and returns a number.
- *
- * A compliant random number generator must satisfy the following
- * requirements. <table border=1 cellpadding=10 cellspacing=0>
- * <caption align=top>Random Number Generator Requirements</caption>
- * <tr><td>To be documented.</td></tr> </table>
- *
- * @{
- */
-
- /**
- * @brief A model of a linear congruential random number generator.
- *
- * A random number generator that produces pseudorandom numbers using the
- * linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$.
- *
- * The template parameter @p _UIntType must be an unsigned integral type
- * large enough to store values up to (__m-1). If the template parameter
- * @p __m is 0, the modulus @p __m used is
- * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
- * parameters @p __a and @p __c must be less than @p __m.
- *
- * The size of the state is @f$ 1 @f$.
- */
- template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
- class linear_congruential
- {
- __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
- // __glibcpp_class_requires(__a < __m && __c < __m)
-
- public:
- /** The type of the generated random value. */
- typedef _UIntType result_type;
-
- /** The multiplier. */
- static const _UIntType multiplier = __a;
- /** An increment. */
- static const _UIntType increment = __c;
- /** The modulus. */
- static const _UIntType modulus = __m;
-
- /**
- * Constructs a %linear_congruential random number generator engine with
- * seed @p __s. The default seed value is 1.
- *
- * @param __s The initial seed value.
- */
- explicit
- linear_congruential(unsigned long __x0 = 1)
- { this->seed(__x0); }
-
- /**
- * Constructs a %linear_congruential random number generator engine
- * seeded from the generator function @p __g.
- *
- * @param __g The seed generator function.
- */
- template<class _Gen>
- linear_congruential(_Gen& __g)
- { this->seed(__g); }
-
- /**
- * Reseeds the %linear_congruential random number generator engine
- * sequence to the seed @g __s.
- *
- * @param __s The new seed.
- */
- void
- seed(unsigned long __s = 1);
-
- /**
- * Reseeds the %linear_congruential random number generator engine
- * sequence using values from the generator function @p __g.
- *
- * @param __g the seed generator function.
- */
- template<class _Gen>
- void
- seed(_Gen& __g)
- { seed(__g, typename is_fundamental<_Gen>::type()); }
-
- /**
- * Gets the smallest possible value in the output range.
- *
- * The minimum depends on the @p __c parameter: if it is zero, the
- * minimum generated must be > 0, otherwise 0 is allowed.
- */
- result_type
- min() const
- { return (__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) ? 1 : 0; }
-
- /**
- * Gets the largest possible value in the output range.
- */
- result_type
- max() const
- { return __m - 1; }
-
- /**
- * Gets the next random number in the sequence.
- */
- result_type
- operator()();
-
- /**
- * Compares two linear congruential random number generator
- * objects of the same type for equality.
- *
- * @param __lhs A linear congruential random number generator object.
- * @param __rhs Another linear congruential random number generator obj.
- *
- * @returns true if the two objects are equal, false otherwise.
- */
- friend bool
- operator==(const linear_congruential& __lhs,
- const linear_congruential& __rhs)
- { return __lhs._M_x == __rhs._M_x; }
-
- /**
- * Compares two linear congruential random number generator
- * objects of the same type for inequality.
- *
- * @param __lhs A linear congruential random number generator object.
- * @param __rhs Another linear congruential random number generator obj.
- *
- * @returns true if the two objects are not equal, false otherwise.
- */
- friend bool
- operator!=(const linear_congruential& __lhs,
- const linear_congruential& __rhs)
- { return !(__lhs == __rhs); }
-
- /**
- * Writes the textual representation of the state x(i) of x to @p __os.
- *
- * @param __os The output stream.
- * @param __lcr A % linear_congruential random number generator.
- * @returns __os.
- */
- template<class _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
- _UIntType1 __m1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const linear_congruential<_UIntType1, __a1, __c1,
- __m1>& __lcr);
-
- /**
- * Sets the state of the engine by reading its textual
- * representation from @p __is.
- *
- * The textual representation must have been previously written using an
- * output stream whose imbued locale and whose type's template
- * specialization arguments _CharT and _Traits were the same as those of
- * @p __is.
- *
- * @param __is The input stream.
- * @param __lcr A % linear_congruential random number generator.
- * @returns __is.
- */
- template<class _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
- _UIntType1 __m1,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- linear_congruential<_UIntType1, __a1, __c1, __m1>& __lcr);
-
- private:
- template<class _Gen>
- void
- seed(_Gen& __g, true_type)
- { return seed(static_cast<unsigned long>(__g)); }
-
- template<class _Gen>
- void
- seed(_Gen& __g, false_type);
-
- _UIntType _M_x;
- };
-
- /**
- * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
- */
- typedef linear_congruential<unsigned long, 16807, 0, 2147483647> minstd_rand0;
-
- /**
- * An alternative LCR (Lehmer Generator function) .
- */
- typedef linear_congruential<unsigned long, 48271, 0, 2147483647> minstd_rand;
-
-
- /**
- * A generalized feedback shift register discrete random number generator.
- *
- * This algorithm avoids multiplication and division and is designed to be
- * friendly to a pipelined architecture. If the parameters are chosen
- * correctly, this generator will produce numbers with a very long period and
- * fairly good apparent entropy, although still not cryptographically strong.
- *
- * The best way to use this generator is with the predefined mt19937 class.
- *
- * This algorithm was originally invented by Makoto Matsumoto and
- * Takuji Nishimura.
- *
- * @var word_size The number of bits in each element of the state vector.
- * @var state_size The degree of recursion.
- * @var shift_size The period parameter.
- * @var mask_bits The separation point bit index.
- * @var parameter_a The last row of the twist matrix.
- * @var output_u The first right-shift tempering matrix parameter.
- * @var output_s The first left-shift tempering matrix parameter.
- * @var output_b The first left-shift tempering matrix mask.
- * @var output_t The second left-shift tempering matrix parameter.
- * @var output_c The second left-shift tempering matrix mask.
- * @var output_l The second right-shift tempering matrix parameter.
- */
- template<class _UIntType, int __w, int __n, int __m, int __r,
- _UIntType __a, int __u, int __s, _UIntType __b, int __t,
- _UIntType __c, int __l>
- class mersenne_twister
- {
- __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
-
- public:
- // types
- typedef _UIntType result_type;
-
- // parameter values
- static const int word_size = __w;
- static const int state_size = __n;
- static const int shift_size = __m;
- static const int mask_bits = __r;
- static const _UIntType parameter_a = __a;
- static const int output_u = __u;
- static const int output_s = __s;
- static const _UIntType output_b = __b;
- static const int output_t = __t;
- static const _UIntType output_c = __c;
- static const int output_l = __l;
-
- // constructors and member function
- mersenne_twister()
- { seed(); }
-
- explicit
- mersenne_twister(unsigned long __value)
- { seed(__value); }
-
- template<class _Gen>
- mersenne_twister(_Gen& __g)
- { seed(__g); }
-
- void
- seed()
- { seed(5489UL); }
-
- void
- seed(unsigned long __value);
-
- template<class _Gen>
- void
- seed(_Gen& __g)
- { seed(__g, typename is_fundamental<_Gen>::type()); }
-
- result_type
- min() const
- { return 0; };
-
- result_type
- max() const
- { return __detail::_Shift<_UIntType, __w>::__value - 1; }
-
- result_type
- operator()();
-
- /**
- * Compares two % mersenne_twister random number generator objects of
- * the same type for equality.
- *
- * @param __lhs A % mersenne_twister random number generator object.
- * @param __rhs Another % mersenne_twister random number generator
- * object.
- *
- * @returns true if the two objects are equal, false otherwise.
- */
- friend bool
- operator==(const mersenne_twister& __lhs,
- const mersenne_twister& __rhs)
- { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
-
- /**
- * Compares two % mersenne_twister random number generator objects of
- * the same type for inequality.
- *
- * @param __lhs A % mersenne_twister random number generator object.
- * @param __rhs Another % mersenne_twister random number generator
- * object.
- *
- * @returns true if the two objects are not equal, false otherwise.
- */
- friend bool
- operator!=(const mersenne_twister& __lhs,
- const mersenne_twister& __rhs)
- { return !(__lhs == __rhs); }
-
- /**
- * Inserts the current state of a % mersenne_twister random number
- * generator engine @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A % mersenne_twister random number generator engine.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<class _UIntType1, int __w1, int __n1, int __m1, int __r1,
- _UIntType1 __a1, int __u1, int __s1, _UIntType1 __b1, int __t1,
- _UIntType1 __c1, int __l1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1,
- __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x);
-
- /**
- * Extracts the current state of a % mersenne_twister random number
- * generator engine @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A % mersenne_twister random number generator engine.
- *
- * @returns The input stream with the state of @p __x extracted or in
- * an error state.
- */
- template<class _UIntType1, int __w1, int __n1, int __m1, int __r1,
- _UIntType1 __a1, int __u1, int __s1, _UIntType1 __b1, int __t1,
- _UIntType1 __c1, int __l1,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1,
- __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x);
-
- private:
- template<class _Gen>
- void
- seed(_Gen& __g, true_type)
- { return seed(static_cast<unsigned long>(__g)); }
-
- template<class _Gen>
- void
- seed(_Gen& __g, false_type);
-
- _UIntType _M_x[state_size];
- int _M_p;
- };
-
- /**
- * The classic Mersenne Twister.
- *
- * Reference:
- * M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
- * Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions
- * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
- */
- typedef mersenne_twister<
- unsigned long, 32, 624, 397, 31,
- 0x9908b0dful, 11, 7,
- 0x9d2c5680ul, 15,
- 0xefc60000ul, 18
- > mt19937;
-
-
- /**
- * @brief The Marsaglia-Zaman generator.
- *
- * This is a model of a Generalized Fibonacci discrete random number
- * generator, sometimes referred to as the SWC generator.
- *
- * A discrete random number generator that produces pseudorandom
- * numbers using @f$x_{i}\leftarrow(x_{i - s} - x_{i - r} -
- * carry_{i-1}) \bmod m @f$.
- *
- * The size of the state is @f$ r @f$
- * and the maximum period of the generator is @f$ m^r - m^s -1 @f$.
- *
- * N1688[4.13] says "the template parameter _IntType shall denote an integral
- * type large enough to store values up to m."
- *
- * @var _M_x The state of the generator. This is a ring buffer.
- * @var _M_carry The carry.
- * @var _M_p Current index of x(i - r).
- */
- template<typename _IntType, _IntType __m, int __s, int __r>
- class subtract_with_carry
- {
- __glibcxx_class_requires(_IntType, _IntegerConcept)
-
- public:
- /** The type of the generated random value. */
- typedef _IntType result_type;
-
- // parameter values
- static const _IntType modulus = __m;
- static const int long_lag = __r;
- static const int short_lag = __s;
-
- /**
- * Constructs a default-initialized % subtract_with_carry random number
- * generator.
- */
- subtract_with_carry()
- { this->seed(); }
-
- /**
- * Constructs an explicitly seeded % subtract_with_carry random number
- * generator.
- */
- explicit
- subtract_with_carry(unsigned long __value)
- { this->seed(__value); }
-
- /**
- * Constructs a %subtract_with_carry random number generator engine
- * seeded from the generator function @p __g.
- *
- * @param __g The seed generator function.
- */
- template<class _Gen>
- subtract_with_carry(_Gen& __g)
- { this->seed(__g); }
-
- /**
- * Seeds the initial state @f$ x_0 @f$ of the random number generator.
- *
- * N1688[4.19] modifies this as follows. If @p __value == 0,
- * sets value to 19780503. In any case, with a linear
- * congruential generator lcg(i) having parameters @f$ m_{lcg} =
- * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
- * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
- * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
- * set carry to 1, otherwise sets carry to 0.
- */
- void
- seed(unsigned long __value = 19780503);
-
- /**
- * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry
- * random number generator.
- */
- template<class _Gen>
- void
- seed(_Gen& __g)
- { seed(__g, typename is_fundamental<_Gen>::type()); }
-
- /**
- * Gets the inclusive minimum value of the range of random integers
- * returned by this generator.
- */
- result_type
- min() const
- { return 0; }
-
- /**
- * Gets the inclusive maximum value of the range of random integers
- * returned by this generator.
- */
- result_type
- max() const
- { return this->modulus - 1; }
-
- /**
- * Gets the next random number in the sequence.
- */
- result_type
- operator()();
-
- /**
- * Compares two % subtract_with_carry random number generator objects of
- * the same type for equality.
- *
- * @param __lhs A % subtract_with_carry random number generator object.
- * @param __rhs Another % subtract_with_carry random number generator
- * object.
- *
- * @returns true if the two objects are equal, false otherwise.
- */
- friend bool
- operator==(const subtract_with_carry& __lhs,
- const subtract_with_carry& __rhs)
- { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
-
- /**
- * Compares two % subtract_with_carry random number generator objects of
- * the same type for inequality.
- *
- * @param __lhs A % subtract_with_carry random number generator object.
- * @param __rhs Another % subtract_with_carry random number generator
- * object.
- *
- * @returns true if the two objects are not equal, false otherwise.
- */
- friend bool
- operator!=(const subtract_with_carry& __lhs,
- const subtract_with_carry& __rhs)
- { return !(__lhs == __rhs); }
-
- /**
- * Inserts the current state of a % subtract_with_carry random number
- * generator engine @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A % subtract_with_carry random number generator engine.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _IntType1, _IntType1 __m1, int __s1, int __r1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const subtract_with_carry<_IntType1, __m1, __s1,
- __r1>& __x);
-
- /**
- * Extracts the current state of a % subtract_with_carry random number
- * generator engine @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A % subtract_with_carry random number generator engine.
- *
- * @returns The input stream with the state of @p __x extracted or in
- * an error state.
- */
- template<typename _IntType1, _IntType1 __m1, int __s1, int __r1,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- subtract_with_carry<_IntType1, __m1, __s1, __r1>& __x);
-
- private:
- template<class _Gen>
- void
- seed(_Gen& __g, true_type)
- { return seed(static_cast<unsigned long>(__g)); }
-
- template<class _Gen>
- void
- seed(_Gen& __g, false_type);
-
- typedef typename __gnu_cxx::__add_unsigned<_IntType>::__type _UIntType;
-
- _UIntType _M_x[long_lag];
- _UIntType _M_carry;
- int _M_p;
- };
-
-
- /**
- * @brief The Marsaglia-Zaman generator (floats version).
- *
- * @var _M_x The state of the generator. This is a ring buffer.
- * @var _M_carry The carry.
- * @var _M_p Current index of x(i - r).
- * @var _M_npows Precomputed negative powers of 2.
- */
- template<typename _RealType, int __w, int __s, int __r>
- class subtract_with_carry_01
- {
- public:
- /** The type of the generated random value. */
- typedef _RealType result_type;
-
- // parameter values
- static const int word_size = __w;
- static const int long_lag = __r;
- static const int short_lag = __s;
-
- /**
- * Constructs a default-initialized % subtract_with_carry_01 random
- * number generator.
- */
- subtract_with_carry_01()
- {
- this->seed();
- _M_initialize_npows();
- }
-
- /**
- * Constructs an explicitly seeded % subtract_with_carry_01 random number
- * generator.
- */
- explicit
- subtract_with_carry_01(unsigned long __value)
- {
- this->seed(__value);
- _M_initialize_npows();
- }
-
- /**
- * Constructs a % subtract_with_carry_01 random number generator engine
- * seeded from the generator function @p __g.
- *
- * @param __g The seed generator function.
- */
- template<class _Gen>
- subtract_with_carry_01(_Gen& __g)
- {
- this->seed(__g);
- _M_initialize_npows();
- }
-
- /**
- * Seeds the initial state @f$ x_0 @f$ of the random number generator.
- */
- void
- seed(unsigned long __value = 19780503);
-
- /**
- * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry_01
- * random number generator.
- */
- template<class _Gen>
- void
- seed(_Gen& __g)
- { seed(__g, typename is_fundamental<_Gen>::type()); }
-
- /**
- * Gets the minimum value of the range of random floats
- * returned by this generator.
- */
- result_type
- min() const
- { return 0.0; }
-
- /**
- * Gets the maximum value of the range of random floats
- * returned by this generator.
- */
- result_type
- max() const
- { return 1.0; }
-
- /**
- * Gets the next random number in the sequence.
- */
- result_type
- operator()();
-
- /**
- * Compares two % subtract_with_carry_01 random number generator objects
- * of the same type for equality.
- *
- * @param __lhs A % subtract_with_carry_01 random number
- * generator object.
- * @param __rhs Another % subtract_with_carry_01 random number generator
- * object.
- *
- * @returns true if the two objects are equal, false otherwise.
- */
- friend bool
- operator==(const subtract_with_carry_01& __lhs,
- const subtract_with_carry_01& __rhs)
- {
- for (int __i = 0; __i < long_lag; ++__i)
- if (!std::equal(__lhs._M_x[__i], __lhs._M_x[__i] + __n,
- __rhs._M_x[__i]))
- return false;
- return true;
- }
-
- /**
- * Compares two % subtract_with_carry_01 random number generator objects
- * of the same type for inequality.
- *
- * @param __lhs A % subtract_with_carry_01 random number
- * generator object.
- *
- * @param __rhs Another % subtract_with_carry_01 random number generator
- * object.
- *
- * @returns true if the two objects are not equal, false otherwise.
- */
- friend bool
- operator!=(const subtract_with_carry_01& __lhs,
- const subtract_with_carry_01& __rhs)
- { return !(__lhs == __rhs); }
-
- /**
- * Inserts the current state of a % subtract_with_carry_01 random number
- * generator engine @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A % subtract_with_carry_01 random number generator engine.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, int __w1, int __s1, int __r1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const subtract_with_carry_01<_RealType1, __w1, __s1,
- __r1>& __x);
-
- /**
- * Extracts the current state of a % subtract_with_carry_01 random number
- * generator engine @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A % subtract_with_carry_01 random number generator engine.
- *
- * @returns The input stream with the state of @p __x extracted or in
- * an error state.
- */
- template<typename _RealType1, int __w1, int __s1, int __r1,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- subtract_with_carry_01<_RealType1, __w1, __s1, __r1>& __x);
-
- private:
- template<class _Gen>
- void
- seed(_Gen& __g, true_type)
- { return seed(static_cast<unsigned long>(__g)); }
-
- template<class _Gen>
- void
- seed(_Gen& __g, false_type);
-
- void
- _M_initialize_npows();
-
- static const int __n = (__w + 31) / 32;
-
- typedef __detail::_UInt32Type _UInt32Type;
- _UInt32Type _M_x[long_lag][__n];
- _RealType _M_npows[__n];
- _UInt32Type _M_carry;
- int _M_p;
- };
-
- typedef subtract_with_carry_01<float, 24, 10, 24> ranlux_base_01;
-
- // _GLIBCXX_RESOLVE_LIB_DEFECTS
- // 508. Bad parameters for ranlux64_base_01.
- typedef subtract_with_carry_01<double, 48, 5, 12> ranlux64_base_01;
-
-
- /**
- * Produces random numbers from some base engine by discarding blocks of
- * data.
- *
- * 0 <= @p __r <= @p __p
- */
- template<class _UniformRandomNumberGenerator, int __p, int __r>
- class discard_block
- {
- // __glibcxx_class_requires(typename base_type::result_type,
- // ArithmeticTypeConcept)
-
- public:
- /** The type of the underlying generator engine. */
- typedef _UniformRandomNumberGenerator base_type;
- /** The type of the generated random value. */
- typedef typename base_type::result_type result_type;
-
- // parameter values
- static const int block_size = __p;
- static const int used_block = __r;
-
- /**
- * Constructs a default %discard_block engine.
- *
- * The underlying engine is default constructed as well.
- */
- discard_block()
- : _M_n(0) { }
-
- /**
- * Copy constructs a %discard_block engine.
- *
- * Copies an existing base class random number generator.
- * @param rng An existing (base class) engine object.
- */
- explicit
- discard_block(const base_type& __rng)
- : _M_b(__rng), _M_n(0) { }
-
- /**
- * Seed constructs a %discard_block engine.
- *
- * Constructs the underlying generator engine seeded with @p __s.
- * @param __s A seed value for the base class engine.
- */
- explicit
- discard_block(unsigned long __s)
- : _M_b(__s), _M_n(0) { }
-
- /**
- * Generator construct a %discard_block engine.
- *
- * @param __g A seed generator function.
- */
- template<class _Gen>
- discard_block(_Gen& __g)
- : _M_b(__g), _M_n(0) { }
-
- /**
- * Reseeds the %discard_block object with the default seed for the
- * underlying base class generator engine.
- */
- void seed()
- {
- _M_b.seed();
- _M_n = 0;
- }
-
- /**
- * Reseeds the %discard_block object with the given seed generator
- * function.
- * @param __g A seed generator function.
- */
- template<class _Gen>
- void seed(_Gen& __g)
- {
- _M_b.seed(__g);
- _M_n = 0;
- }
-
- /**
- * Gets a const reference to the underlying generator engine object.
- */
- const base_type&
- base() const
- { return _M_b; }
-
- /**
- * Gets the minimum value in the generated random number range.
- */
- result_type
- min() const
- { return _M_b.min(); }
-
- /**
- * Gets the maximum value in the generated random number range.
- */
- result_type
- max() const
- { return _M_b.max(); }
-
- /**
- * Gets the next value in the generated random number sequence.
- */
- result_type
- operator()();
-
- /**
- * Compares two %discard_block random number generator objects of
- * the same type for equality.
- *
- * @param __lhs A %discard_block random number generator object.
- * @param __rhs Another %discard_block random number generator
- * object.
- *
- * @returns true if the two objects are equal, false otherwise.
- */
- friend bool
- operator==(const discard_block& __lhs, const discard_block& __rhs)
- { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); }
-
- /**
- * Compares two %discard_block random number generator objects of
- * the same type for inequality.
- *
- * @param __lhs A %discard_block random number generator object.
- * @param __rhs Another %discard_block random number generator
- * object.
- *
- * @returns true if the two objects are not equal, false otherwise.
- */
- friend bool
- operator!=(const discard_block& __lhs, const discard_block& __rhs)
- { return !(__lhs == __rhs); }
-
- /**
- * Inserts the current state of a %discard_block random number
- * generator engine @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %discard_block random number generator engine.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<class _UniformRandomNumberGenerator1, int __p1, int __r1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const discard_block<_UniformRandomNumberGenerator1,
- __p1, __r1>& __x);
-
- /**
- * Extracts the current state of a % subtract_with_carry random number
- * generator engine @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %discard_block random number generator engine.
- *
- * @returns The input stream with the state of @p __x extracted or in
- * an error state.
- */
- template<class _UniformRandomNumberGenerator1, int __p1, int __r1,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- discard_block<_UniformRandomNumberGenerator1,
- __p1, __r1>& __x);
-
- private:
- base_type _M_b;
- int _M_n;
- };
-
-
- /**
- * James's luxury-level-3 integer adaptation of Luescher's generator.
- */
- typedef discard_block<
- subtract_with_carry<unsigned long, (1UL << 24), 10, 24>,
- 223,
- 24
- > ranlux3;
-
- /**
- * James's luxury-level-4 integer adaptation of Luescher's generator.
- */
- typedef discard_block<
- subtract_with_carry<unsigned long, (1UL << 24), 10, 24>,
- 389,
- 24
- > ranlux4;
-
- typedef discard_block<
- subtract_with_carry_01<float, 24, 10, 24>,
- 223,
- 24
- > ranlux3_01;
-
- typedef discard_block<
- subtract_with_carry_01<float, 24, 10, 24>,
- 389,
- 24
- > ranlux4_01;
-
-
- /**
- * A random number generator adaptor class that combines two random number
- * generator engines into a single output sequence.
- */
- template<class _UniformRandomNumberGenerator1, int __s1,
- class _UniformRandomNumberGenerator2, int __s2>
- class xor_combine
- {
- // __glibcxx_class_requires(typename _UniformRandomNumberGenerator1::
- // result_type, ArithmeticTypeConcept)
- // __glibcxx_class_requires(typename _UniformRandomNumberGenerator2::
- // result_type, ArithmeticTypeConcept)
-
- public:
- /** The type of the first underlying generator engine. */
- typedef _UniformRandomNumberGenerator1 base1_type;
- /** The type of the second underlying generator engine. */
- typedef _UniformRandomNumberGenerator2 base2_type;
-
- private:
- typedef typename base1_type::result_type _Result_type1;
- typedef typename base2_type::result_type _Result_type2;
-
- public:
- /** The type of the generated random value. */
- typedef typename __gnu_cxx::__conditional_type<(sizeof(_Result_type1)
- > sizeof(_Result_type2)),
- _Result_type1, _Result_type2>::__type result_type;
-
- // parameter values
- static const int shift1 = __s1;
- static const int shift2 = __s2;
-
- // constructors and member function
- xor_combine()
- : _M_b1(), _M_b2()
- { _M_initialize_max(); }
-
- xor_combine(const base1_type& __rng1, const base2_type& __rng2)
- : _M_b1(__rng1), _M_b2(__rng2)
- { _M_initialize_max(); }
-
- xor_combine(unsigned long __s)
- : _M_b1(__s), _M_b2(__s + 1)
- { _M_initialize_max(); }
-
- template<class _Gen>
- xor_combine(_Gen& __g)
- : _M_b1(__g), _M_b2(__g)
- { _M_initialize_max(); }
-
- void
- seed()
- {
- _M_b1.seed();
- _M_b2.seed();
- }
-
- template<class _Gen>
- void
- seed(_Gen& __g)
- {
- _M_b1.seed(__g);
- _M_b2.seed(__g);
- }
-
- const base1_type&
- base1() const
- { return _M_b1; }
-
- const base2_type&
- base2() const
- { return _M_b2; }
-
- result_type
- min() const
- { return 0; }
-
- result_type
- max() const
- { return _M_max; }
-
- /**
- * Gets the next random number in the sequence.
- */
- // NB: Not exactly the TR1 formula, per N2079 instead.
- result_type
- operator()()
- {
- return ((result_type(_M_b1() - _M_b1.min()) << shift1)
- ^ (result_type(_M_b2() - _M_b2.min()) << shift2));
- }
-
- /**
- * Compares two %xor_combine random number generator objects of
- * the same type for equality.
- *
- * @param __lhs A %xor_combine random number generator object.
- * @param __rhs Another %xor_combine random number generator
- * object.
- *
- * @returns true if the two objects are equal, false otherwise.
- */
- friend bool
- operator==(const xor_combine& __lhs, const xor_combine& __rhs)
- {
- return (__lhs.base1() == __rhs.base1())
- && (__lhs.base2() == __rhs.base2());
- }
-
- /**
- * Compares two %xor_combine random number generator objects of
- * the same type for inequality.
- *
- * @param __lhs A %xor_combine random number generator object.
- * @param __rhs Another %xor_combine random number generator
- * object.
- *
- * @returns true if the two objects are not equal, false otherwise.
- */
- friend bool
- operator!=(const xor_combine& __lhs, const xor_combine& __rhs)
- { return !(__lhs == __rhs); }
-
- /**
- * Inserts the current state of a %xor_combine random number
- * generator engine @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %xor_combine random number generator engine.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<class _UniformRandomNumberGenerator11, int __s11,
- class _UniformRandomNumberGenerator21, int __s21,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const xor_combine<_UniformRandomNumberGenerator11, __s11,
- _UniformRandomNumberGenerator21, __s21>& __x);
-
- /**
- * Extracts the current state of a %xor_combine random number
- * generator engine @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %xor_combine random number generator engine.
- *
- * @returns The input stream with the state of @p __x extracted or in
- * an error state.
- */
- template<class _UniformRandomNumberGenerator11, int __s11,
- class _UniformRandomNumberGenerator21, int __s21,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- xor_combine<_UniformRandomNumberGenerator11, __s11,
- _UniformRandomNumberGenerator21, __s21>& __x);
-
- private:
- void
- _M_initialize_max();
-
- result_type
- _M_initialize_max_aux(result_type, result_type, int);
-
- base1_type _M_b1;
- base2_type _M_b2;
- result_type _M_max;
- };
-
-
- /**
- * A standard interface to a platform-specific non-deterministic
- * random number generator (if any are available).
- */
- class random_device
- {
- public:
- // types
- typedef unsigned int result_type;
-
- // constructors, destructors and member functions
-
-#ifdef _GLIBCXX_USE_RANDOM_TR1
-
- explicit
- random_device(const std::string& __token = "/dev/urandom")
- {
- if ((__token != "/dev/urandom" && __token != "/dev/random")
- || !(_M_file = std::fopen(__token.c_str(), "rb")))
- std::__throw_runtime_error(__N("random_device::"
- "random_device(const std::string&)"));
- }
-
- ~random_device()
- { std::fclose(_M_file); }
-
-#else
-
- explicit
- random_device(const std::string& __token = "mt19937")
- : _M_mt(_M_strtoul(__token)) { }
-
- private:
- static unsigned long
- _M_strtoul(const std::string& __str)
- {
- unsigned long __ret = 5489UL;
- if (__str != "mt19937")
- {
- const char* __nptr = __str.c_str();
- char* __endptr;
- __ret = std::strtoul(__nptr, &__endptr, 0);
- if (*__nptr == '\0' || *__endptr != '\0')
- std::__throw_runtime_error(__N("random_device::_M_strtoul"
- "(const std::string&)"));
- }
- return __ret;
- }
-
- public:
-
-#endif
-
- result_type
- min() const
- { return std::numeric_limits<result_type>::min(); }
-
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
-
- double
- entropy() const
- { return 0.0; }
-
- result_type
- operator()()
- {
-#ifdef _GLIBCXX_USE_RANDOM_TR1
- result_type __ret;
- std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
- 1, _M_file);
- return __ret;
-#else
- return _M_mt();
-#endif
- }
-
- private:
- random_device(const random_device&);
- void operator=(const random_device&);
-
-#ifdef _GLIBCXX_USE_RANDOM_TR1
- FILE* _M_file;
-#else
- mt19937 _M_mt;
-#endif
- };
-
- /* @} */ // group tr1_random_generators
-
- /**
- * @defgroup tr1_random_distributions Random Number Distributions
- * @ingroup tr1_random
- * @{
- */
-
- /**
- * @defgroup tr1_random_distributions_discrete Discrete Distributions
- * @ingroup tr1_random_distributions
- * @{
- */
-
- /**
- * @brief Uniform discrete distribution for random numbers.
- * A discrete random distribution on the range @f$[min, max]@f$ with equal
- * probability throughout the range.
- */
- template<typename _IntType = int>
- class uniform_int
- {
- __glibcxx_class_requires(_IntType, _IntegerConcept)
-
- public:
- /** The type of the parameters of the distribution. */
- typedef _IntType input_type;
- /** The type of the range of the distribution. */
- typedef _IntType result_type;
-
- public:
- /**
- * Constructs a uniform distribution object.
- */
- explicit
- uniform_int(_IntType __min = 0, _IntType __max = 9)
- : _M_min(__min), _M_max(__max)
- {
- _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max);
- }
-
- /**
- * Gets the inclusive lower bound of the distribution range.
- */
- result_type
- min() const
- { return _M_min; }
-
- /**
- * Gets the inclusive upper bound of the distribution range.
- */
- result_type
- max() const
- { return _M_max; }
-
- /**
- * Resets the distribution state.
- *
- * Does nothing for the uniform integer distribution.
- */
- void
- reset() { }
-
- /**
- * Gets a uniformly distributed random number in the range
- * @f$(min, max)@f$.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- {
- typedef typename _UniformRandomNumberGenerator::result_type
- _UResult_type;
- return _M_call(__urng, _M_min, _M_max,
- typename is_integral<_UResult_type>::type());
- }
-
- /**
- * Gets a uniform random number in the range @f$[0, n)@f$.
- *
- * This function is aimed at use with std::random_shuffle.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng, result_type __n)
- {
- typedef typename _UniformRandomNumberGenerator::result_type
- _UResult_type;
- return _M_call(__urng, 0, __n - 1,
- typename is_integral<_UResult_type>::type());
- }
-
- /**
- * Inserts a %uniform_int random number distribution @p __x into the
- * output stream @p os.
- *
- * @param __os An output stream.
- * @param __x A %uniform_int random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _IntType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const uniform_int<_IntType1>& __x);
-
- /**
- * Extracts a %uniform_int random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %uniform_int random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _IntType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- uniform_int<_IntType1>& __x);
-
- private:
- template<typename _UniformRandomNumberGenerator>
- result_type
- _M_call(_UniformRandomNumberGenerator& __urng,
- result_type __min, result_type __max, true_type);
-
- template<typename _UniformRandomNumberGenerator>
- result_type
- _M_call(_UniformRandomNumberGenerator& __urng,
- result_type __min, result_type __max, false_type)
- {
- return result_type((__urng() - __urng.min())
- / (__urng.max() - __urng.min())
- * (__max - __min + 1)) + __min;
- }
-
- _IntType _M_min;
- _IntType _M_max;
- };
-
-
- /**
- * @brief A Bernoulli random number distribution.
- *
- * Generates a sequence of true and false values with likelihood @f$ p @f$
- * that true will come up and @f$ (1 - p) @f$ that false will appear.
- */
- class bernoulli_distribution
- {
- public:
- typedef int input_type;
- typedef bool result_type;
-
- public:
- /**
- * Constructs a Bernoulli distribution with likelihood @p p.
- *
- * @param __p [IN] The likelihood of a true result being returned. Must
- * be in the interval @f$ [0, 1] @f$.
- */
- explicit
- bernoulli_distribution(double __p = 0.5)
- : _M_p(__p)
- {
- _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
- }
-
- /**
- * Gets the @p p parameter of the distribution.
- */
- double
- p() const
- { return _M_p; }
-
- /**
- * Resets the distribution state.
- *
- * Does nothing for a Bernoulli distribution.
- */
- void
- reset() { }
-
- /**
- * Gets the next value in the Bernoullian sequence.
- */
- template<class _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- {
- if ((__urng() - __urng.min()) < _M_p * (__urng.max() - __urng.min()))
- return true;
- return false;
- }
-
- /**
- * Inserts a %bernoulli_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %bernoulli_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const bernoulli_distribution& __x);
-
- /**
- * Extracts a %bernoulli_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %bernoulli_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- bernoulli_distribution& __x)
- { return __is >> __x._M_p; }
-
- private:
- double _M_p;
- };
-
-
- /**
- * @brief A discrete geometric random number distribution.
- *
- * The formula for the geometric probability mass function is
- * @f$ p(i) = (1 - p)p^{i-1} @f$ where @f$ p @f$ is the parameter of the
- * distribution.
- */
- template<typename _IntType = int, typename _RealType = double>
- class geometric_distribution
- {
- public:
- // types
- typedef _RealType input_type;
- typedef _IntType result_type;
-
- // constructors and member function
- explicit
- geometric_distribution(const _RealType& __p = _RealType(0.5))
- : _M_p(__p)
- {
- _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0));
- _M_initialize();
- }
-
- /**
- * Gets the distribution parameter @p p.
- */
- _RealType
- p() const
- { return _M_p; }
-
- void
- reset() { }
-
- template<class _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng);
-
- /**
- * Inserts a %geometric_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %geometric_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _IntType1, typename _RealType1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const geometric_distribution<_IntType1, _RealType1>& __x);
-
- /**
- * Extracts a %geometric_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %geometric_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- geometric_distribution& __x)
- {
- __is >> __x._M_p;
- __x._M_initialize();
- return __is;
- }
-
- private:
- void
- _M_initialize()
- { _M_log_p = std::log(_M_p); }
-
- _RealType _M_p;
- _RealType _M_log_p;
- };
-
-
- template<typename _RealType>
- class normal_distribution;
-
- /**
- * @brief A discrete Poisson random number distribution.
- *
- * The formula for the Poisson probability mass function is
- * @f$ p(i) = \frac{mean^i}{i!} e^{-mean} @f$ where @f$ mean @f$ is the
- * parameter of the distribution.
- */
- template<typename _IntType = int, typename _RealType = double>
- class poisson_distribution
- {
- public:
- // types
- typedef _RealType input_type;
- typedef _IntType result_type;
-
- // constructors and member function
- explicit
- poisson_distribution(const _RealType& __mean = _RealType(1))
- : _M_mean(__mean), _M_nd()
- {
- _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
- _M_initialize();
- }
-
- /**
- * Gets the distribution parameter @p mean.
- */
- _RealType
- mean() const
- { return _M_mean; }
-
- void
- reset()
- { _M_nd.reset(); }
-
- template<class _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng);
-
- /**
- * Inserts a %poisson_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %poisson_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _IntType1, typename _RealType1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const poisson_distribution<_IntType1, _RealType1>& __x);
-
- /**
- * Extracts a %poisson_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %poisson_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _IntType1, typename _RealType1,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- poisson_distribution<_IntType1, _RealType1>& __x);
-
- private:
- void
- _M_initialize();
-
- // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
- normal_distribution<_RealType> _M_nd;
-
- _RealType _M_mean;
-
- // Hosts either log(mean) or the threshold of the simple method.
- _RealType _M_lm_thr;
-#if _GLIBCXX_USE_C99_MATH_TR1
- _RealType _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
-#endif
- };
-
-
- /**
- * @brief A discrete binomial random number distribution.
- *
- * The formula for the binomial probability mass function is
- * @f$ p(i) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$
- * and @f$ p @f$ are the parameters of the distribution.
- */
- template<typename _IntType = int, typename _RealType = double>
- class binomial_distribution
- {
- public:
- // types
- typedef _RealType input_type;
- typedef _IntType result_type;
-
- // constructors and member function
- explicit
- binomial_distribution(_IntType __t = 1,
- const _RealType& __p = _RealType(0.5))
- : _M_t(__t), _M_p(__p), _M_nd()
- {
- _GLIBCXX_DEBUG_ASSERT((_M_t >= 0) && (_M_p >= 0.0) && (_M_p <= 1.0));
- _M_initialize();
- }
-
- /**
- * Gets the distribution @p t parameter.
- */
- _IntType
- t() const
- { return _M_t; }
-
- /**
- * Gets the distribution @p p parameter.
- */
- _RealType
- p() const
- { return _M_p; }
-
- void
- reset()
- { _M_nd.reset(); }
-
- template<class _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng);
-
- /**
- * Inserts a %binomial_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %binomial_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _IntType1, typename _RealType1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const binomial_distribution<_IntType1, _RealType1>& __x);
-
- /**
- * Extracts a %binomial_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %binomial_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _IntType1, typename _RealType1,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- binomial_distribution<_IntType1, _RealType1>& __x);
-
- private:
- void
- _M_initialize();
-
- template<class _UniformRandomNumberGenerator>
- result_type
- _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
-
- // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
- normal_distribution<_RealType> _M_nd;
-
- _RealType _M_q;
-#if _GLIBCXX_USE_C99_MATH_TR1
- _RealType _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
- _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
-#endif
- _RealType _M_p;
- _IntType _M_t;
-
- bool _M_easy;
- };
-
- /* @} */ // group tr1_random_distributions_discrete
-
- /**
- * @defgroup tr1_random_distributions_continuous Continuous Distributions
- * @ingroup tr1_random_distributions
- * @{
- */
-
- /**
- * @brief Uniform continuous distribution for random numbers.
- *
- * A continuous random distribution on the range [min, max) with equal
- * probability throughout the range. The URNG should be real-valued and
- * deliver number in the range [0, 1).
- */
- template<typename _RealType = double>
- class uniform_real
- {
- public:
- // types
- typedef _RealType input_type;
- typedef _RealType result_type;
-
- public:
- /**
- * Constructs a uniform_real object.
- *
- * @param __min [IN] The lower bound of the distribution.
- * @param __max [IN] The upper bound of the distribution.
- */
- explicit
- uniform_real(_RealType __min = _RealType(0),
- _RealType __max = _RealType(1))
- : _M_min(__min), _M_max(__max)
- {
- _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max);
- }
-
- result_type
- min() const
- { return _M_min; }
-
- result_type
- max() const
- { return _M_max; }
-
- void
- reset() { }
-
- template<class _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return (__urng() * (_M_max - _M_min)) + _M_min; }
-
- /**
- * Inserts a %uniform_real random number distribution @p __x into the
- * output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %uniform_real random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const uniform_real<_RealType1>& __x);
-
- /**
- * Extracts a %uniform_real random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %uniform_real random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- uniform_real<_RealType1>& __x);
-
- private:
- _RealType _M_min;
- _RealType _M_max;
- };
-
-
- /**
- * @brief An exponential continuous distribution for random numbers.
- *
- * The formula for the exponential probability mass function is
- * @f$ p(x) = \lambda e^{-\lambda x} @f$.
- *
- * <table border=1 cellpadding=10 cellspacing=0>
- * <caption align=top>Distribution Statistics</caption>
- * <tr><td>Mean</td><td>@f$ \frac{1}{\lambda} @f$</td></tr>
- * <tr><td>Median</td><td>@f$ \frac{\ln 2}{\lambda} @f$</td></tr>
- * <tr><td>Mode</td><td>@f$ zero @f$</td></tr>
- * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
- * <tr><td>Standard Deviation</td><td>@f$ \frac{1}{\lambda} @f$</td></tr>
- * </table>
- */
- template<typename _RealType = double>
- class exponential_distribution
- {
- public:
- // types
- typedef _RealType input_type;
- typedef _RealType result_type;
-
- public:
- /**
- * Constructs an exponential distribution with inverse scale parameter
- * @f$ \lambda @f$.
- */
- explicit
- exponential_distribution(const result_type& __lambda = result_type(1))
- : _M_lambda(__lambda)
- {
- _GLIBCXX_DEBUG_ASSERT(_M_lambda > 0);
- }
-
- /**
- * Gets the inverse scale parameter of the distribution.
- */
- _RealType
- lambda() const
- { return _M_lambda; }
-
- /**
- * Resets the distribution.
- *
- * Has no effect on exponential distributions.
- */
- void
- reset() { }
-
- template<class _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return -std::log(__urng()) / _M_lambda; }
-
- /**
- * Inserts a %exponential_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %exponential_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const exponential_distribution<_RealType1>& __x);
-
- /**
- * Extracts a %exponential_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %exponential_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- exponential_distribution& __x)
- { return __is >> __x._M_lambda; }
-
- private:
- result_type _M_lambda;
- };
-
-
- /**
- * @brief A normal continuous distribution for random numbers.
- *
- * The formula for the normal probability mass function is
- * @f$ p(x) = \frac{1}{\sigma \sqrt{2 \pi}}
- * e^{- \frac{{x - mean}^ {2}}{2 \sigma ^ {2}} } @f$.
- */
- template<typename _RealType = double>
- class normal_distribution
- {
- public:
- // types
- typedef _RealType input_type;
- typedef _RealType result_type;
-
- public:
- /**
- * Constructs a normal distribution with parameters @f$ mean @f$ and
- * @f$ \sigma @f$.
- */
- explicit
- normal_distribution(const result_type& __mean = result_type(0),
- const result_type& __sigma = result_type(1))
- : _M_mean(__mean), _M_sigma(__sigma), _M_saved_available(false)
- {
- _GLIBCXX_DEBUG_ASSERT(_M_sigma > 0);
- }
-
- /**
- * Gets the mean of the distribution.
- */
- _RealType
- mean() const
- { return _M_mean; }
-
- /**
- * Gets the @f$ \sigma @f$ of the distribution.
- */
- _RealType
- sigma() const
- { return _M_sigma; }
-
- /**
- * Resets the distribution.
- */
- void
- reset()
- { _M_saved_available = false; }
-
- template<class _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng);
-
- /**
- * Inserts a %normal_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %normal_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const normal_distribution<_RealType1>& __x);
-
- /**
- * Extracts a %normal_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %normal_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- normal_distribution<_RealType1>& __x);
-
- private:
- result_type _M_mean;
- result_type _M_sigma;
- result_type _M_saved;
- bool _M_saved_available;
- };
-
-
- /**
- * @brief A gamma continuous distribution for random numbers.
- *
- * The formula for the gamma probability mass function is
- * @f$ p(x) = \frac{1}{\Gamma(\alpha)} x^{\alpha - 1} e^{-x} @f$.
- */
- template<typename _RealType = double>
- class gamma_distribution
- {
- public:
- // types
- typedef _RealType input_type;
- typedef _RealType result_type;
-
- public:
- /**
- * Constructs a gamma distribution with parameters @f$ \alpha @f$.
- */
- explicit
- gamma_distribution(const result_type& __alpha_val = result_type(1))
- : _M_alpha(__alpha_val)
- {
- _GLIBCXX_DEBUG_ASSERT(_M_alpha > 0);
- _M_initialize();
- }
-
- /**
- * Gets the @f$ \alpha @f$ of the distribution.
- */
- _RealType
- alpha() const
- { return _M_alpha; }
-
- /**
- * Resets the distribution.
- */
- void
- reset() { }
-
- template<class _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng);
-
- /**
- * Inserts a %gamma_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %gamma_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const gamma_distribution<_RealType1>& __x);
-
- /**
- * Extracts a %gamma_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %gamma_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- gamma_distribution& __x)
- {
- __is >> __x._M_alpha;
- __x._M_initialize();
- return __is;
- }
-
- private:
- void
- _M_initialize();
-
- result_type _M_alpha;
-
- // Hosts either lambda of GB or d of modified Vaduva's.
- result_type _M_l_d;
- };
-
- /* @} */ // group tr1_random_distributions_continuous
- /* @} */ // group tr1_random_distributions
- /* @} */ // group tr1_random
-
-_GLIBCXX_END_NAMESPACE_TR1
-}
-
-#include <tr1_impl/random.tcc>
diff --git a/libstdc++-v3/include/tr1_impl/random.tcc b/libstdc++-v3/include/tr1_impl/random.tcc
index 2b0f6957b14..e69de29bb2d 100644
--- a/libstdc++-v3/include/tr1_impl/random.tcc
+++ b/libstdc++-v3/include/tr1_impl/random.tcc
@@ -1,1582 +0,0 @@
-// random number generation (out of line) -*- C++ -*-
-
-// Copyright (C) 2007 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library. This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING. If not, write to the Free
-// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
-
-// As a special exception, you may use this file as part of a free software
-// library without restriction. Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License. This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
-
-/** @file tr1_impl/random.tcc
- * This is an internal header file, included by other library headers.
- * You should not attempt to use it directly.
- */
-
-namespace std
-{
-_GLIBCXX_BEGIN_NAMESPACE_TR1
-
- /*
- * (Further) implementation-space details.
- */
- namespace __detail
- {
- // General case for x = (ax + c) mod m -- use Schrage's algorithm to avoid
- // integer overflow.
- //
- // Because a and c are compile-time integral constants the compiler kindly
- // elides any unreachable paths.
- //
- // Preconditions: a > 0, m > 0.
- //
- template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool>
- struct _Mod
- {
- static _Tp
- __calc(_Tp __x)
- {
- if (__a == 1)
- __x %= __m;
- else
- {
- static const _Tp __q = __m / __a;
- static const _Tp __r = __m % __a;
-
- _Tp __t1 = __a * (__x % __q);
- _Tp __t2 = __r * (__x / __q);
- if (__t1 >= __t2)
- __x = __t1 - __t2;
- else
- __x = __m - __t2 + __t1;
- }
-
- if (__c != 0)
- {
- const _Tp __d = __m - __x;
- if (__d > __c)
- __x += __c;
- else
- __x = __c - __d;
- }
- return __x;
- }
- };
-
- // Special case for m == 0 -- use unsigned integer overflow as modulo
- // operator.
- template<typename _Tp, _Tp __a, _Tp __c, _Tp __m>
- struct _Mod<_Tp, __a, __c, __m, true>
- {
- static _Tp
- __calc(_Tp __x)
- { return __a * __x + __c; }
- };
- } // namespace __detail
-
- /**
- * Seeds the LCR with integral value @p __x0, adjusted so that the
- * ring identity is never a member of the convergence set.
- */
- template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
- void
- linear_congruential<_UIntType, __a, __c, __m>::
- seed(unsigned long __x0)
- {
- if ((__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0)
- && (__detail::__mod<_UIntType, 1, 0, __m>(__x0) == 0))
- _M_x = __detail::__mod<_UIntType, 1, 0, __m>(1);
- else
- _M_x = __detail::__mod<_UIntType, 1, 0, __m>(__x0);
- }
-
- /**
- * Seeds the LCR engine with a value generated by @p __g.
- */
- template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
- template<class _Gen>
- void
- linear_congruential<_UIntType, __a, __c, __m>::
- seed(_Gen& __g, false_type)
- {
- _UIntType __x0 = __g();
- if ((__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0)
- && (__detail::__mod<_UIntType, 1, 0, __m>(__x0) == 0))
- _M_x = __detail::__mod<_UIntType, 1, 0, __m>(1);
- else
- _M_x = __detail::__mod<_UIntType, 1, 0, __m>(__x0);
- }
-
- /**
- * Gets the next generated value in sequence.
- */
- template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
- typename linear_congruential<_UIntType, __a, __c, __m>::result_type
- linear_congruential<_UIntType, __a, __c, __m>::
- operator()()
- {
- _M_x = __detail::__mod<_UIntType, __a, __c, __m>(_M_x);
- return _M_x;
- }
-
- template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
- typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const linear_congruential<_UIntType, __a, __c, __m>& __lcr)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
- __os.fill(__os.widen(' '));
-
- __os << __lcr._M_x;
-
- __os.flags(__flags);
- __os.fill(__fill);
- return __os;
- }
-
- template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
- typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- linear_congruential<_UIntType, __a, __c, __m>& __lcr)
- {
- typedef std::basic_istream<_CharT, _Traits> __istream_type;
- typedef typename __istream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __is.flags();
- __is.flags(__ios_base::dec);
-
- __is >> __lcr._M_x;
-
- __is.flags(__flags);
- return __is;
- }
-
-
- template<class _UIntType, int __w, int __n, int __m, int __r,
- _UIntType __a, int __u, int __s,
- _UIntType __b, int __t, _UIntType __c, int __l>
- void
- mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
- __b, __t, __c, __l>::
- seed(unsigned long __value)
- {
- _M_x[0] = __detail::__mod<_UIntType, 1, 0,
- __detail::_Shift<_UIntType, __w>::__value>(__value);
-
- for (int __i = 1; __i < state_size; ++__i)
- {
- _UIntType __x = _M_x[__i - 1];
- __x ^= __x >> (__w - 2);
- __x *= 1812433253ul;
- __x += __i;
- _M_x[__i] = __detail::__mod<_UIntType, 1, 0,
- __detail::_Shift<_UIntType, __w>::__value>(__x);
- }
- _M_p = state_size;
- }
-
- template<class _UIntType, int __w, int __n, int __m, int __r,
- _UIntType __a, int __u, int __s,
- _UIntType __b, int __t, _UIntType __c, int __l>
- template<class _Gen>
- void
- mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
- __b, __t, __c, __l>::
- seed(_Gen& __gen, false_type)
- {
- for (int __i = 0; __i < state_size; ++__i)
- _M_x[__i] = __detail::__mod<_UIntType, 1, 0,
- __detail::_Shift<_UIntType, __w>::__value>(__gen());
- _M_p = state_size;
- }
-
- template<class _UIntType, int __w, int __n, int __m, int __r,
- _UIntType __a, int __u, int __s,
- _UIntType __b, int __t, _UIntType __c, int __l>
- typename
- mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
- __b, __t, __c, __l>::result_type
- mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
- __b, __t, __c, __l>::
- operator()()
- {
- // Reload the vector - cost is O(n) amortized over n calls.
- if (_M_p >= state_size)
- {
- const _UIntType __upper_mask = (~_UIntType()) << __r;
- const _UIntType __lower_mask = ~__upper_mask;
-
- for (int __k = 0; __k < (__n - __m); ++__k)
- {
- _UIntType __y = ((_M_x[__k] & __upper_mask)
- | (_M_x[__k + 1] & __lower_mask));
- _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
- ^ ((__y & 0x01) ? __a : 0));
- }
-
- for (int __k = (__n - __m); __k < (__n - 1); ++__k)
- {
- _UIntType __y = ((_M_x[__k] & __upper_mask)
- | (_M_x[__k + 1] & __lower_mask));
- _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
- ^ ((__y & 0x01) ? __a : 0));
- }
-
- _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
- | (_M_x[0] & __lower_mask));
- _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
- ^ ((__y & 0x01) ? __a : 0));
- _M_p = 0;
- }
-
- // Calculate o(x(i)).
- result_type __z = _M_x[_M_p++];
- __z ^= (__z >> __u);
- __z ^= (__z << __s) & __b;
- __z ^= (__z << __t) & __c;
- __z ^= (__z >> __l);
-
- return __z;
- }
-
- template<class _UIntType, int __w, int __n, int __m, int __r,
- _UIntType __a, int __u, int __s, _UIntType __b, int __t,
- _UIntType __c, int __l,
- typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const mersenne_twister<_UIntType, __w, __n, __m,
- __r, __a, __u, __s, __b, __t, __c, __l>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const _CharT __space = __os.widen(' ');
- __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
- __os.fill(__space);
-
- for (int __i = 0; __i < __n - 1; ++__i)
- __os << __x._M_x[__i] << __space;
- __os << __x._M_x[__n - 1];
-
- __os.flags(__flags);
- __os.fill(__fill);
- return __os;
- }
-
- template<class _UIntType, int __w, int __n, int __m, int __r,
- _UIntType __a, int __u, int __s, _UIntType __b, int __t,
- _UIntType __c, int __l,
- typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- mersenne_twister<_UIntType, __w, __n, __m,
- __r, __a, __u, __s, __b, __t, __c, __l>& __x)
- {
- typedef std::basic_istream<_CharT, _Traits> __istream_type;
- typedef typename __istream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __is.flags();
- __is.flags(__ios_base::dec | __ios_base::skipws);
-
- for (int __i = 0; __i < __n; ++__i)
- __is >> __x._M_x[__i];
-
- __is.flags(__flags);
- return __is;
- }
-
-
- template<typename _IntType, _IntType __m, int __s, int __r>
- void
- subtract_with_carry<_IntType, __m, __s, __r>::
- seed(unsigned long __value)
- {
- if (__value == 0)
- __value = 19780503;
-
- std::_GLIBCXX_TR1 linear_congruential<unsigned long, 40014, 0, 2147483563>
- __lcg(__value);
-
- for (int __i = 0; __i < long_lag; ++__i)
- _M_x[__i] = __detail::__mod<_UIntType, 1, 0, modulus>(__lcg());
-
- _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
- _M_p = 0;
- }
-
- template<typename _IntType, _IntType __m, int __s, int __r>
- template<class _Gen>
- void
- subtract_with_carry<_IntType, __m, __s, __r>::
- seed(_Gen& __gen, false_type)
- {
- const int __n = (std::numeric_limits<_UIntType>::digits + 31) / 32;
-
- for (int __i = 0; __i < long_lag; ++__i)
- {
- _UIntType __tmp = 0;
- _UIntType __factor = 1;
- for (int __j = 0; __j < __n; ++__j)
- {
- __tmp += __detail::__mod<__detail::_UInt32Type, 1, 0, 0>
- (__gen()) * __factor;
- __factor *= __detail::_Shift<_UIntType, 32>::__value;
- }
- _M_x[__i] = __detail::__mod<_UIntType, 1, 0, modulus>(__tmp);
- }
- _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
- _M_p = 0;
- }
-
- template<typename _IntType, _IntType __m, int __s, int __r>
- typename subtract_with_carry<_IntType, __m, __s, __r>::result_type
- subtract_with_carry<_IntType, __m, __s, __r>::
- operator()()
- {
- // Derive short lag index from current index.
- int __ps = _M_p - short_lag;
- if (__ps < 0)
- __ps += long_lag;
-
- // Calculate new x(i) without overflow or division.
- // NB: Thanks to the requirements for _IntType, _M_x[_M_p] + _M_carry
- // cannot overflow.
- _UIntType __xi;
- if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
- {
- __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
- _M_carry = 0;
- }
- else
- {
- __xi = modulus - _M_x[_M_p] - _M_carry + _M_x[__ps];
- _M_carry = 1;
- }
- _M_x[_M_p] = __xi;
-
- // Adjust current index to loop around in ring buffer.
- if (++_M_p >= long_lag)
- _M_p = 0;
-
- return __xi;
- }
-
- template<typename _IntType, _IntType __m, int __s, int __r,
- typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const subtract_with_carry<_IntType, __m, __s, __r>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const _CharT __space = __os.widen(' ');
- __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
- __os.fill(__space);
-
- for (int __i = 0; __i < __r; ++__i)
- __os << __x._M_x[__i] << __space;
- __os << __x._M_carry;
-
- __os.flags(__flags);
- __os.fill(__fill);
- return __os;
- }
-
- template<typename _IntType, _IntType __m, int __s, int __r,
- typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- subtract_with_carry<_IntType, __m, __s, __r>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __istream_type;
- typedef typename __istream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __is.flags();
- __is.flags(__ios_base::dec | __ios_base::skipws);
-
- for (int __i = 0; __i < __r; ++__i)
- __is >> __x._M_x[__i];
- __is >> __x._M_carry;
-
- __is.flags(__flags);
- return __is;
- }
-
-
- template<typename _RealType, int __w, int __s, int __r>
- void
- subtract_with_carry_01<_RealType, __w, __s, __r>::
- _M_initialize_npows()
- {
- for (int __j = 0; __j < __n; ++__j)
-#if _GLIBCXX_USE_C99_MATH_TR1
- _M_npows[__j] = std::_GLIBCXX_TR1 ldexp(_RealType(1), -__w + __j * 32);
-#else
- _M_npows[__j] = std::pow(_RealType(2), -__w + __j * 32);
-#endif
- }
-
- template<typename _RealType, int __w, int __s, int __r>
- void
- subtract_with_carry_01<_RealType, __w, __s, __r>::
- seed(unsigned long __value)
- {
- if (__value == 0)
- __value = 19780503;
-
- // _GLIBCXX_RESOLVE_LIB_DEFECTS
- // 512. Seeding subtract_with_carry_01 from a single unsigned long.
- std::_GLIBCXX_TR1 linear_congruential<unsigned long, 40014, 0, 2147483563>
- __lcg(__value);
-
- this->seed(__lcg);
- }
-
- template<typename _RealType, int __w, int __s, int __r>
- template<class _Gen>
- void
- subtract_with_carry_01<_RealType, __w, __s, __r>::
- seed(_Gen& __gen, false_type)
- {
- for (int __i = 0; __i < long_lag; ++__i)
- {
- for (int __j = 0; __j < __n - 1; ++__j)
- _M_x[__i][__j] = __detail::__mod<_UInt32Type, 1, 0, 0>(__gen());
- _M_x[__i][__n - 1] = __detail::__mod<_UInt32Type, 1, 0,
- __detail::_Shift<_UInt32Type, __w % 32>::__value>(__gen());
- }
-
- _M_carry = 1;
- for (int __j = 0; __j < __n; ++__j)
- if (_M_x[long_lag - 1][__j] != 0)
- {
- _M_carry = 0;
- break;
- }
-
- _M_p = 0;
- }
-
- template<typename _RealType, int __w, int __s, int __r>
- typename subtract_with_carry_01<_RealType, __w, __s, __r>::result_type
- subtract_with_carry_01<_RealType, __w, __s, __r>::
- operator()()
- {
- // Derive short lag index from current index.
- int __ps = _M_p - short_lag;
- if (__ps < 0)
- __ps += long_lag;
-
- _UInt32Type __new_carry;
- for (int __j = 0; __j < __n - 1; ++__j)
- {
- if (_M_x[__ps][__j] > _M_x[_M_p][__j]
- || (_M_x[__ps][__j] == _M_x[_M_p][__j] && _M_carry == 0))
- __new_carry = 0;
- else
- __new_carry = 1;
-
- _M_x[_M_p][__j] = _M_x[__ps][__j] - _M_x[_M_p][__j] - _M_carry;
- _M_carry = __new_carry;
- }
-
- if (_M_x[__ps][__n - 1] > _M_x[_M_p][__n - 1]
- || (_M_x[__ps][__n - 1] == _M_x[_M_p][__n - 1] && _M_carry == 0))
- __new_carry = 0;
- else
- __new_carry = 1;
-
- _M_x[_M_p][__n - 1] = __detail::__mod<_UInt32Type, 1, 0,
- __detail::_Shift<_UInt32Type, __w % 32>::__value>
- (_M_x[__ps][__n - 1] - _M_x[_M_p][__n - 1] - _M_carry);
- _M_carry = __new_carry;
-
- result_type __ret = 0.0;
- for (int __j = 0; __j < __n; ++__j)
- __ret += _M_x[_M_p][__j] * _M_npows[__j];
-
- // Adjust current index to loop around in ring buffer.
- if (++_M_p >= long_lag)
- _M_p = 0;
-
- return __ret;
- }
-
- template<typename _RealType, int __w, int __s, int __r,
- typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const subtract_with_carry_01<_RealType, __w, __s, __r>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const _CharT __space = __os.widen(' ');
- __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
- __os.fill(__space);
-
- for (int __i = 0; __i < __r; ++__i)
- for (int __j = 0; __j < __x.__n; ++__j)
- __os << __x._M_x[__i][__j] << __space;
- __os << __x._M_carry;
-
- __os.flags(__flags);
- __os.fill(__fill);
- return __os;
- }
-
- template<typename _RealType, int __w, int __s, int __r,
- typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- subtract_with_carry_01<_RealType, __w, __s, __r>& __x)
- {
- typedef std::basic_istream<_CharT, _Traits> __istream_type;
- typedef typename __istream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __is.flags();
- __is.flags(__ios_base::dec | __ios_base::skipws);
-
- for (int __i = 0; __i < __r; ++__i)
- for (int __j = 0; __j < __x.__n; ++__j)
- __is >> __x._M_x[__i][__j];
- __is >> __x._M_carry;
-
- __is.flags(__flags);
- return __is;
- }
-
-
- template<class _UniformRandomNumberGenerator, int __p, int __r>
- typename discard_block<_UniformRandomNumberGenerator,
- __p, __r>::result_type
- discard_block<_UniformRandomNumberGenerator, __p, __r>::
- operator()()
- {
- if (_M_n >= used_block)
- {
- while (_M_n < block_size)
- {
- _M_b();
- ++_M_n;
- }
- _M_n = 0;
- }
- ++_M_n;
- return _M_b();
- }
-
- template<class _UniformRandomNumberGenerator, int __p, int __r,
- typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const discard_block<_UniformRandomNumberGenerator,
- __p, __r>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const _CharT __space = __os.widen(' ');
- __os.flags(__ios_base::dec | __ios_base::fixed
- | __ios_base::left);
- __os.fill(__space);
-
- __os << __x._M_b << __space << __x._M_n;
-
- __os.flags(__flags);
- __os.fill(__fill);
- return __os;
- }
-
- template<class _UniformRandomNumberGenerator, int __p, int __r,
- typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- discard_block<_UniformRandomNumberGenerator, __p, __r>& __x)
- {
- typedef std::basic_istream<_CharT, _Traits> __istream_type;
- typedef typename __istream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __is.flags();
- __is.flags(__ios_base::dec | __ios_base::skipws);
-
- __is >> __x._M_b >> __x._M_n;
-
- __is.flags(__flags);
- return __is;
- }
-
-
- template<class _UniformRandomNumberGenerator1, int __s1,
- class _UniformRandomNumberGenerator2, int __s2>
- void
- xor_combine<_UniformRandomNumberGenerator1, __s1,
- _UniformRandomNumberGenerator2, __s2>::
- _M_initialize_max()
- {
- const int __w = std::numeric_limits<result_type>::digits;
-
- const result_type __m1 =
- std::min(result_type(_M_b1.max() - _M_b1.min()),
- __detail::_Shift<result_type, __w - __s1>::__value - 1);
-
- const result_type __m2 =
- std::min(result_type(_M_b2.max() - _M_b2.min()),
- __detail::_Shift<result_type, __w - __s2>::__value - 1);
-
- // NB: In TR1 s1 is not required to be >= s2.
- if (__s1 < __s2)
- _M_max = _M_initialize_max_aux(__m2, __m1, __s2 - __s1) << __s1;
- else
- _M_max = _M_initialize_max_aux(__m1, __m2, __s1 - __s2) << __s2;
- }
-
- template<class _UniformRandomNumberGenerator1, int __s1,
- class _UniformRandomNumberGenerator2, int __s2>
- typename xor_combine<_UniformRandomNumberGenerator1, __s1,
- _UniformRandomNumberGenerator2, __s2>::result_type
- xor_combine<_UniformRandomNumberGenerator1, __s1,
- _UniformRandomNumberGenerator2, __s2>::
- _M_initialize_max_aux(result_type __a, result_type __b, int __d)
- {
- const result_type __two2d = result_type(1) << __d;
- const result_type __c = __a * __two2d;
-
- if (__a == 0 || __b < __two2d)
- return __c + __b;
-
- const result_type __t = std::max(__c, __b);
- const result_type __u = std::min(__c, __b);
-
- result_type __ub = __u;
- result_type __p;
- for (__p = 0; __ub != 1; __ub >>= 1)
- ++__p;
-
- const result_type __two2p = result_type(1) << __p;
- const result_type __k = __t / __two2p;
-
- if (__k & 1)
- return (__k + 1) * __two2p - 1;
-
- if (__c >= __b)
- return (__k + 1) * __two2p + _M_initialize_max_aux((__t % __two2p)
- / __two2d,
- __u % __two2p, __d);
- else
- return (__k + 1) * __two2p + _M_initialize_max_aux((__u % __two2p)
- / __two2d,
- __t % __two2p, __d);
- }
-
- template<class _UniformRandomNumberGenerator1, int __s1,
- class _UniformRandomNumberGenerator2, int __s2,
- typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const xor_combine<_UniformRandomNumberGenerator1, __s1,
- _UniformRandomNumberGenerator2, __s2>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const _CharT __space = __os.widen(' ');
- __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
- __os.fill(__space);
-
- __os << __x.base1() << __space << __x.base2();
-
- __os.flags(__flags);
- __os.fill(__fill);
- return __os;
- }
-
- template<class _UniformRandomNumberGenerator1, int __s1,
- class _UniformRandomNumberGenerator2, int __s2,
- typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- xor_combine<_UniformRandomNumberGenerator1, __s1,
- _UniformRandomNumberGenerator2, __s2>& __x)
- {
- typedef std::basic_istream<_CharT, _Traits> __istream_type;
- typedef typename __istream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __is.flags();
- __is.flags(__ios_base::skipws);
-
- __is >> __x._M_b1 >> __x._M_b2;
-
- __is.flags(__flags);
- return __is;
- }
-
-
- template<typename _IntType>
- template<typename _UniformRandomNumberGenerator>
- typename uniform_int<_IntType>::result_type
- uniform_int<_IntType>::
- _M_call(_UniformRandomNumberGenerator& __urng,
- result_type __min, result_type __max, true_type)
- {
- // XXX Must be fixed to work well for *arbitrary* __urng.max(),
- // __urng.min(), __max, __min. Currently works fine only in the
- // most common case __urng.max() - __urng.min() >= __max - __min,
- // with __urng.max() > __urng.min() >= 0.
- typedef typename __gnu_cxx::__add_unsigned<typename
- _UniformRandomNumberGenerator::result_type>::__type __urntype;
- typedef typename __gnu_cxx::__add_unsigned<result_type>::__type
- __utype;
- typedef typename __gnu_cxx::__conditional_type<(sizeof(__urntype)
- > sizeof(__utype)),
- __urntype, __utype>::__type __uctype;
-
- result_type __ret;
-
- const __urntype __urnmin = __urng.min();
- const __urntype __urnmax = __urng.max();
- const __urntype __urnrange = __urnmax - __urnmin;
- const __uctype __urange = __max - __min;
- const __uctype __udenom = (__urnrange <= __urange
- ? 1 : __urnrange / (__urange + 1));
- do
- __ret = (__urntype(__urng()) - __urnmin) / __udenom;
- while (__ret > __max - __min);
-
- return __ret + __min;
- }
-
- template<typename _IntType, typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const uniform_int<_IntType>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const _CharT __space = __os.widen(' ');
- __os.flags(__ios_base::scientific | __ios_base::left);
- __os.fill(__space);
-
- __os << __x.min() << __space << __x.max();
-
- __os.flags(__flags);
- __os.fill(__fill);
- return __os;
- }
-
- template<typename _IntType, typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- uniform_int<_IntType>& __x)
- {
- typedef std::basic_istream<_CharT, _Traits> __istream_type;
- typedef typename __istream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __is.flags();
- __is.flags(__ios_base::dec | __ios_base::skipws);
-
- __is >> __x._M_min >> __x._M_max;
-
- __is.flags(__flags);
- return __is;
- }
-
-
- template<typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const bernoulli_distribution& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const std::streamsize __precision = __os.precision();
- __os.flags(__ios_base::scientific | __ios_base::left);
- __os.fill(__os.widen(' '));
- __os.precision(__gnu_cxx::__numeric_traits<double>::__max_digits10);
-
- __os << __x.p();
-
- __os.flags(__flags);
- __os.fill(__fill);
- __os.precision(__precision);
- return __os;
- }
-
-
- template<typename _IntType, typename _RealType>
- template<class _UniformRandomNumberGenerator>
- typename geometric_distribution<_IntType, _RealType>::result_type
- geometric_distribution<_IntType, _RealType>::
- operator()(_UniformRandomNumberGenerator& __urng)
- {
- // About the epsilon thing see this thread:
- // http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00971.html
- const _RealType __naf =
- (1 - std::numeric_limits<_RealType>::epsilon()) / 2;
- // The largest _RealType convertible to _IntType.
- const _RealType __thr =
- std::numeric_limits<_IntType>::max() + __naf;
-
- _RealType __cand;
- do
- __cand = std::ceil(std::log(__urng()) / _M_log_p);
- while (__cand >= __thr);
-
- return result_type(__cand + __naf);
- }
-
- template<typename _IntType, typename _RealType,
- typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const geometric_distribution<_IntType, _RealType>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const std::streamsize __precision = __os.precision();
- __os.flags(__ios_base::scientific | __ios_base::left);
- __os.fill(__os.widen(' '));
- __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
-
- __os << __x.p();
-
- __os.flags(__flags);
- __os.fill(__fill);
- __os.precision(__precision);
- return __os;
- }
-
-
- template<typename _IntType, typename _RealType>
- void
- poisson_distribution<_IntType, _RealType>::
- _M_initialize()
- {
-#if _GLIBCXX_USE_C99_MATH_TR1
- if (_M_mean >= 12)
- {
- const _RealType __m = std::floor(_M_mean);
- _M_lm_thr = std::log(_M_mean);
- _M_lfm = std::_GLIBCXX_TR1 lgamma(__m + 1);
- _M_sm = std::sqrt(__m);
-
- const _RealType __pi_4 = 0.7853981633974483096156608458198757L;
- const _RealType __dx = std::sqrt(2 * __m * std::log(32 * __m
- / __pi_4));
- _M_d = std::_GLIBCXX_TR1 round(std::max(_RealType(6),
- std::min(__m, __dx)));
- const _RealType __cx = 2 * __m + _M_d;
- _M_scx = std::sqrt(__cx / 2);
- _M_1cx = 1 / __cx;
-
- _M_c2b = std::sqrt(__pi_4 * __cx) * std::exp(_M_1cx);
- _M_cb = 2 * __cx * std::exp(-_M_d * _M_1cx * (1 + _M_d / 2)) / _M_d;
- }
- else
-#endif
- _M_lm_thr = std::exp(-_M_mean);
- }
-
- /**
- * A rejection algorithm when mean >= 12 and a simple method based
- * upon the multiplication of uniform random variates otherwise.
- * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1
- * is defined.
- *
- * Reference:
- * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag,
- * New York, 1986, Ch. X, Sects. 3.3 & 3.4 (+ Errata!).
- */
- template<typename _IntType, typename _RealType>
- template<class _UniformRandomNumberGenerator>
- typename poisson_distribution<_IntType, _RealType>::result_type
- poisson_distribution<_IntType, _RealType>::
- operator()(_UniformRandomNumberGenerator& __urng)
- {
-#if _GLIBCXX_USE_C99_MATH_TR1
- if (_M_mean >= 12)
- {
- _RealType __x;
-
- // See comments above...
- const _RealType __naf =
- (1 - std::numeric_limits<_RealType>::epsilon()) / 2;
- const _RealType __thr =
- std::numeric_limits<_IntType>::max() + __naf;
-
- const _RealType __m = std::floor(_M_mean);
- // sqrt(pi / 2)
- const _RealType __spi_2 = 1.2533141373155002512078826424055226L;
- const _RealType __c1 = _M_sm * __spi_2;
- const _RealType __c2 = _M_c2b + __c1;
- const _RealType __c3 = __c2 + 1;
- const _RealType __c4 = __c3 + 1;
- // e^(1 / 78)
- const _RealType __e178 = 1.0129030479320018583185514777512983L;
- const _RealType __c5 = __c4 + __e178;
- const _RealType __c = _M_cb + __c5;
- const _RealType __2cx = 2 * (2 * __m + _M_d);
-
- bool __reject = true;
- do
- {
- const _RealType __u = __c * __urng();
- const _RealType __e = -std::log(__urng());
-
- _RealType __w = 0.0;
-
- if (__u <= __c1)
- {
- const _RealType __n = _M_nd(__urng);
- const _RealType __y = -std::abs(__n) * _M_sm - 1;
- __x = std::floor(__y);
- __w = -__n * __n / 2;
- if (__x < -__m)
- continue;
- }
- else if (__u <= __c2)
- {
- const _RealType __n = _M_nd(__urng);
- const _RealType __y = 1 + std::abs(__n) * _M_scx;
- __x = std::ceil(__y);
- __w = __y * (2 - __y) * _M_1cx;
- if (__x > _M_d)
- continue;
- }
- else if (__u <= __c3)
- // NB: This case not in the book, nor in the Errata,
- // but should be ok...
- __x = -1;
- else if (__u <= __c4)
- __x = 0;
- else if (__u <= __c5)
- __x = 1;
- else
- {
- const _RealType __v = -std::log(__urng());
- const _RealType __y = _M_d + __v * __2cx / _M_d;
- __x = std::ceil(__y);
- __w = -_M_d * _M_1cx * (1 + __y / 2);
- }
-
- __reject = (__w - __e - __x * _M_lm_thr
- > _M_lfm - std::_GLIBCXX_TR1 lgamma(__x + __m + 1));
-
- __reject |= __x + __m >= __thr;
-
- } while (__reject);
-
- return result_type(__x + __m + __naf);
- }
- else
-#endif
- {
- _IntType __x = 0;
- _RealType __prod = 1.0;
-
- do
- {
- __prod *= __urng();
- __x += 1;
- }
- while (__prod > _M_lm_thr);
-
- return __x - 1;
- }
- }
-
- template<typename _IntType, typename _RealType,
- typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const poisson_distribution<_IntType, _RealType>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const std::streamsize __precision = __os.precision();
- const _CharT __space = __os.widen(' ');
- __os.flags(__ios_base::scientific | __ios_base::left);
- __os.fill(__space);
- __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
-
- __os << __x.mean() << __space << __x._M_nd;
-
- __os.flags(__flags);
- __os.fill(__fill);
- __os.precision(__precision);
- return __os;
- }
-
- template<typename _IntType, typename _RealType,
- typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- poisson_distribution<_IntType, _RealType>& __x)
- {
- typedef std::basic_istream<_CharT, _Traits> __istream_type;
- typedef typename __istream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __is.flags();
- __is.flags(__ios_base::skipws);
-
- __is >> __x._M_mean >> __x._M_nd;
- __x._M_initialize();
-
- __is.flags(__flags);
- return __is;
- }
-
-
- template<typename _IntType, typename _RealType>
- void
- binomial_distribution<_IntType, _RealType>::
- _M_initialize()
- {
- const _RealType __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
-
- _M_easy = true;
-
-#if _GLIBCXX_USE_C99_MATH_TR1
- if (_M_t * __p12 >= 8)
- {
- _M_easy = false;
- const _RealType __np = std::floor(_M_t * __p12);
- const _RealType __pa = __np / _M_t;
- const _RealType __1p = 1 - __pa;
-
- const _RealType __pi_4 = 0.7853981633974483096156608458198757L;
- const _RealType __d1x =
- std::sqrt(__np * __1p * std::log(32 * __np
- / (81 * __pi_4 * __1p)));
- _M_d1 = std::_GLIBCXX_TR1 round(std::max(_RealType(1), __d1x));
- const _RealType __d2x =
- std::sqrt(__np * __1p * std::log(32 * _M_t * __1p
- / (__pi_4 * __pa)));
- _M_d2 = std::_GLIBCXX_TR1 round(std::max(_RealType(1), __d2x));
-
- // sqrt(pi / 2)
- const _RealType __spi_2 = 1.2533141373155002512078826424055226L;
- _M_s1 = std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
- _M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
- _M_c = 2 * _M_d1 / __np;
- _M_a1 = std::exp(_M_c) * _M_s1 * __spi_2;
- const _RealType __a12 = _M_a1 + _M_s2 * __spi_2;
- const _RealType __s1s = _M_s1 * _M_s1;
- _M_a123 = __a12 + (std::exp(_M_d1 / (_M_t * __1p))
- * 2 * __s1s / _M_d1
- * std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
- const _RealType __s2s = _M_s2 * _M_s2;
- _M_s = (_M_a123 + 2 * __s2s / _M_d2
- * std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
- _M_lf = (std::_GLIBCXX_TR1 lgamma(__np + 1)
- + std::_GLIBCXX_TR1 lgamma(_M_t - __np + 1));
- _M_lp1p = std::log(__pa / __1p);
-
- _M_q = -std::log(1 - (__p12 - __pa) / __1p);
- }
- else
-#endif
- _M_q = -std::log(1 - __p12);
- }
-
- template<typename _IntType, typename _RealType>
- template<class _UniformRandomNumberGenerator>
- typename binomial_distribution<_IntType, _RealType>::result_type
- binomial_distribution<_IntType, _RealType>::
- _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t)
- {
- _IntType __x = 0;
- _RealType __sum = 0;
-
- do
- {
- const _RealType __e = -std::log(__urng());
- __sum += __e / (__t - __x);
- __x += 1;
- }
- while (__sum <= _M_q);
-
- return __x - 1;
- }
-
- /**
- * A rejection algorithm when t * p >= 8 and a simple waiting time
- * method - the second in the referenced book - otherwise.
- * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1
- * is defined.
- *
- * Reference:
- * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag,
- * New York, 1986, Ch. X, Sect. 4 (+ Errata!).
- */
- template<typename _IntType, typename _RealType>
- template<class _UniformRandomNumberGenerator>
- typename binomial_distribution<_IntType, _RealType>::result_type
- binomial_distribution<_IntType, _RealType>::
- operator()(_UniformRandomNumberGenerator& __urng)
- {
- result_type __ret;
- const _RealType __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
-
-#if _GLIBCXX_USE_C99_MATH_TR1
- if (!_M_easy)
- {
- _RealType __x;
-
- // See comments above...
- const _RealType __naf =
- (1 - std::numeric_limits<_RealType>::epsilon()) / 2;
- const _RealType __thr =
- std::numeric_limits<_IntType>::max() + __naf;
-
- const _RealType __np = std::floor(_M_t * __p12);
- const _RealType __pa = __np / _M_t;
-
- // sqrt(pi / 2)
- const _RealType __spi_2 = 1.2533141373155002512078826424055226L;
- const _RealType __a1 = _M_a1;
- const _RealType __a12 = __a1 + _M_s2 * __spi_2;
- const _RealType __a123 = _M_a123;
- const _RealType __s1s = _M_s1 * _M_s1;
- const _RealType __s2s = _M_s2 * _M_s2;
-
- bool __reject;
- do
- {
- const _RealType __u = _M_s * __urng();
-
- _RealType __v;
-
- if (__u <= __a1)
- {
- const _RealType __n = _M_nd(__urng);
- const _RealType __y = _M_s1 * std::abs(__n);
- __reject = __y >= _M_d1;
- if (!__reject)
- {
- const _RealType __e = -std::log(__urng());
- __x = std::floor(__y);
- __v = -__e - __n * __n / 2 + _M_c;
- }
- }
- else if (__u <= __a12)
- {
- const _RealType __n = _M_nd(__urng);
- const _RealType __y = _M_s2 * std::abs(__n);
- __reject = __y >= _M_d2;
- if (!__reject)
- {
- const _RealType __e = -std::log(__urng());
- __x = std::floor(-__y);
- __v = -__e - __n * __n / 2;
- }
- }
- else if (__u <= __a123)
- {
- const _RealType __e1 = -std::log(__urng());
- const _RealType __e2 = -std::log(__urng());
-
- const _RealType __y = _M_d1 + 2 * __s1s * __e1 / _M_d1;
- __x = std::floor(__y);
- __v = (-__e2 + _M_d1 * (1 / (_M_t - __np)
- -__y / (2 * __s1s)));
- __reject = false;
- }
- else
- {
- const _RealType __e1 = -std::log(__urng());
- const _RealType __e2 = -std::log(__urng());
-
- const _RealType __y = _M_d2 + 2 * __s2s * __e1 / _M_d2;
- __x = std::floor(-__y);
- __v = -__e2 - _M_d2 * __y / (2 * __s2s);
- __reject = false;
- }
-
- __reject = __reject || __x < -__np || __x > _M_t - __np;
- if (!__reject)
- {
- const _RealType __lfx =
- std::_GLIBCXX_TR1 lgamma(__np + __x + 1)
- + std::_GLIBCXX_TR1 lgamma(_M_t - (__np + __x) + 1);
- __reject = __v > _M_lf - __lfx + __x * _M_lp1p;
- }
-
- __reject |= __x + __np >= __thr;
- }
- while (__reject);
-
- __x += __np + __naf;
-
- const _IntType __z = _M_waiting(__urng, _M_t - _IntType(__x));
- __ret = _IntType(__x) + __z;
- }
- else
-#endif
- __ret = _M_waiting(__urng, _M_t);
-
- if (__p12 != _M_p)
- __ret = _M_t - __ret;
- return __ret;
- }
-
- template<typename _IntType, typename _RealType,
- typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const binomial_distribution<_IntType, _RealType>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const std::streamsize __precision = __os.precision();
- const _CharT __space = __os.widen(' ');
- __os.flags(__ios_base::scientific | __ios_base::left);
- __os.fill(__space);
- __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
-
- __os << __x.t() << __space << __x.p()
- << __space << __x._M_nd;
-
- __os.flags(__flags);
- __os.fill(__fill);
- __os.precision(__precision);
- return __os;
- }
-
- template<typename _IntType, typename _RealType,
- typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- binomial_distribution<_IntType, _RealType>& __x)
- {
- typedef std::basic_istream<_CharT, _Traits> __istream_type;
- typedef typename __istream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __is.flags();
- __is.flags(__ios_base::dec | __ios_base::skipws);
-
- __is >> __x._M_t >> __x._M_p >> __x._M_nd;
- __x._M_initialize();
-
- __is.flags(__flags);
- return __is;
- }
-
-
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const uniform_real<_RealType>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const std::streamsize __precision = __os.precision();
- const _CharT __space = __os.widen(' ');
- __os.flags(__ios_base::scientific | __ios_base::left);
- __os.fill(__space);
- __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
-
- __os << __x.min() << __space << __x.max();
-
- __os.flags(__flags);
- __os.fill(__fill);
- __os.precision(__precision);
- return __os;
- }
-
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- uniform_real<_RealType>& __x)
- {
- typedef std::basic_istream<_CharT, _Traits> __istream_type;
- typedef typename __istream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __is.flags();
- __is.flags(__ios_base::skipws);
-
- __is >> __x._M_min >> __x._M_max;
-
- __is.flags(__flags);
- return __is;
- }
-
-
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const exponential_distribution<_RealType>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const std::streamsize __precision = __os.precision();
- __os.flags(__ios_base::scientific | __ios_base::left);
- __os.fill(__os.widen(' '));
- __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
-
- __os << __x.lambda();
-
- __os.flags(__flags);
- __os.fill(__fill);
- __os.precision(__precision);
- return __os;
- }
-
-
- /**
- * Polar method due to Marsaglia.
- *
- * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag,
- * New York, 1986, Ch. V, Sect. 4.4.
- */
- template<typename _RealType>
- template<class _UniformRandomNumberGenerator>
- typename normal_distribution<_RealType>::result_type
- normal_distribution<_RealType>::
- operator()(_UniformRandomNumberGenerator& __urng)
- {
- result_type __ret;
-
- if (_M_saved_available)
- {
- _M_saved_available = false;
- __ret = _M_saved;
- }
- else
- {
- result_type __x, __y, __r2;
- do
- {
- __x = result_type(2.0) * __urng() - 1.0;
- __y = result_type(2.0) * __urng() - 1.0;
- __r2 = __x * __x + __y * __y;
- }
- while (__r2 > 1.0 || __r2 == 0.0);
-
- const result_type __mult = std::sqrt(-2 * std::log(__r2) / __r2);
- _M_saved = __x * __mult;
- _M_saved_available = true;
- __ret = __y * __mult;
- }
-
- __ret = __ret * _M_sigma + _M_mean;
- return __ret;
- }
-
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const normal_distribution<_RealType>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const std::streamsize __precision = __os.precision();
- const _CharT __space = __os.widen(' ');
- __os.flags(__ios_base::scientific | __ios_base::left);
- __os.fill(__space);
- __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
-
- __os << __x._M_saved_available << __space
- << __x.mean() << __space
- << __x.sigma();
- if (__x._M_saved_available)
- __os << __space << __x._M_saved;
-
- __os.flags(__flags);
- __os.fill(__fill);
- __os.precision(__precision);
- return __os;
- }
-
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- normal_distribution<_RealType>& __x)
- {
- typedef std::basic_istream<_CharT, _Traits> __istream_type;
- typedef typename __istream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __is.flags();
- __is.flags(__ios_base::dec | __ios_base::skipws);
-
- __is >> __x._M_saved_available >> __x._M_mean
- >> __x._M_sigma;
- if (__x._M_saved_available)
- __is >> __x._M_saved;
-
- __is.flags(__flags);
- return __is;
- }
-
-
- template<typename _RealType>
- void
- gamma_distribution<_RealType>::
- _M_initialize()
- {
- if (_M_alpha >= 1)
- _M_l_d = std::sqrt(2 * _M_alpha - 1);
- else
- _M_l_d = (std::pow(_M_alpha, _M_alpha / (1 - _M_alpha))
- * (1 - _M_alpha));
- }
-
- /**
- * Cheng's rejection algorithm GB for alpha >= 1 and a modification
- * of Vaduva's rejection from Weibull algorithm due to Devroye for
- * alpha < 1.
- *
- * References:
- * Cheng, R. C. "The Generation of Gamma Random Variables with Non-integral
- * Shape Parameter." Applied Statistics, 26, 71-75, 1977.
- *
- * Vaduva, I. "Computer Generation of Gamma Gandom Variables by Rejection
- * and Composition Procedures." Math. Operationsforschung and Statistik,
- * Series in Statistics, 8, 545-576, 1977.
- *
- * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag,
- * New York, 1986, Ch. IX, Sect. 3.4 (+ Errata!).
- */
- template<typename _RealType>
- template<class _UniformRandomNumberGenerator>
- typename gamma_distribution<_RealType>::result_type
- gamma_distribution<_RealType>::
- operator()(_UniformRandomNumberGenerator& __urng)
- {
- result_type __x;
-
- bool __reject;
- if (_M_alpha >= 1)
- {
- // alpha - log(4)
- const result_type __b = _M_alpha
- - result_type(1.3862943611198906188344642429163531L);
- const result_type __c = _M_alpha + _M_l_d;
- const result_type __1l = 1 / _M_l_d;
-
- // 1 + log(9 / 2)
- const result_type __k = 2.5040773967762740733732583523868748L;
-
- do
- {
- const result_type __u = __urng();
- const result_type __v = __urng();
-
- const result_type __y = __1l * std::log(__v / (1 - __v));
- __x = _M_alpha * std::exp(__y);
-
- const result_type __z = __u * __v * __v;
- const result_type __r = __b + __c * __y - __x;
-
- __reject = __r < result_type(4.5) * __z - __k;
- if (__reject)
- __reject = __r < std::log(__z);
- }
- while (__reject);
- }
- else
- {
- const result_type __c = 1 / _M_alpha;
-
- do
- {
- const result_type __z = -std::log(__urng());
- const result_type __e = -std::log(__urng());
-
- __x = std::pow(__z, __c);
-
- __reject = __z + __e < _M_l_d + __x;
- }
- while (__reject);
- }
-
- return __x;
- }
-
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const gamma_distribution<_RealType>& __x)
- {
- typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
- typedef typename __ostream_type::ios_base __ios_base;
-
- const typename __ios_base::fmtflags __flags = __os.flags();
- const _CharT __fill = __os.fill();
- const std::streamsize __precision = __os.precision();
- __os.flags(__ios_base::scientific | __ios_base::left);
- __os.fill(__os.widen(' '));
- __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10);
-
- __os << __x.alpha();
-
- __os.flags(__flags);
- __os.fill(__fill);
- __os.precision(__precision);
- return __os;
- }
-
-_GLIBCXX_END_NAMESPACE_TR1
-}
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc
index 5bdd65c2700..9a206bfbc18 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2006, 2007, 2008 Free Software Foundation
+// Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -85,11 +85,12 @@ void* thread_hammer_and_kill(void* opaque_pools)
{
shared_and_weak_pools& pools = *static_cast<shared_and_weak_pools*>(opaque_pools);
// Using the same parameters as in the RNG test cases.
- std::mersenne_twister<
+ std::mersenne_twister_engine<
unsigned long, 32, 624, 397, 31,
- 0x9908b0dful, 11, 7,
+ 0x9908b0dful, 11,
+ 0xfffffffful, 7,
0x9d2c5680ul, 15,
- 0xefc60000ul, 18> rng;
+ 0xefc60000ul, 18, 1812433253ul> rng;
sp_vector_t::iterator cur_shared = pools.shared_pool.begin();
wp_vector_t::iterator cur_weak = pools.weak_pool.begin();
@@ -120,11 +121,13 @@ void* thread_hammer(void* opaque_weak)
{
wp_vector_t& weak_pool = *static_cast<wp_vector_t*>(opaque_weak);
// Using the same parameters as in the RNG test cases.
- std::mersenne_twister<
+ std::mersenne_twister_engine<
unsigned long, 32, 624, 397, 31,
- 0x9908b0dful, 11, 7,
+ 0x9908b0dful, 11,
+ 0xfffffffful, 7,
0x9d2c5680ul, 15,
- 0xefc60000ul, 18> rng;
+ 0xefc60000ul, 18, 1812433253ul> rng;
+
wp_vector_t::iterator cur_weak = weak_pool.begin();
for (unsigned int i = 0; i < HAMMER_REPEAT; ++i)
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc
index 20c2da146e0..f98cbfeb089 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2006, 2007, 2008 Free Software Foundation
+// Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -87,12 +87,13 @@ void* thread_hammer_and_kill(void* opaque_pools)
{
shared_and_weak_pools& pools = *static_cast<shared_and_weak_pools*>(opaque_pools);
// Using the same parameters as in the RNG test cases.
- std::mersenne_twister<
+ std::mersenne_twister_engine<
unsigned long, 32, 624, 397, 31,
- 0x9908b0dful, 11, 7,
+ 0x9908b0dful, 11,
+ 0xfffffffful, 7,
0x9d2c5680ul, 15,
- 0xefc60000ul, 18> rng;
-
+ 0xefc60000ul, 18, 1812433253ul> rng;
+
sp_vector_t::iterator cur_shared = pools.shared_pool.begin();
wp_vector_t::iterator cur_weak = pools.weak_pool.begin();
@@ -122,11 +123,13 @@ void* thread_hammer(void* opaque_weak)
{
wp_vector_t& weak_pool = *static_cast<wp_vector_t*>(opaque_weak);
// Using the same parameters as in the RNG test cases.
- std::mersenne_twister<
+ std::mersenne_twister_engine<
unsigned long, 32, 624, 397, 31,
- 0x9908b0dful, 11, 7,
+ 0x9908b0dful, 11,
+ 0xfffffffful, 7,
0x9d2c5680ul, 15,
- 0xefc60000ul, 18> rng;
+ 0xefc60000ul, 18, 1812433253ul> rng;
+
wp_vector_t::iterator cur_weak = weak_pool.begin();
for (unsigned int i = 0; i < HAMMER_REPEAT; ++i)
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/random/std_c++0x_neg.cc b/libstdc++-v3/testsuite/26_numerics/headers/random/std_c++0x_neg.cc
index 9b028bc0324..e91efd17539 100644
--- a/libstdc++-v3/testsuite/26_numerics/headers/random/std_c++0x_neg.cc
+++ b/libstdc++-v3/testsuite/26_numerics/headers/random/std_c++0x_neg.cc
@@ -19,7 +19,7 @@
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
-#include <tuple> // { dg-excess-errors "In file included from" }
+#include <random> // { dg-excess-errors "In file included from" }
// { dg-error "upcoming ISO" "" { target *-*-* } 36 }
diff --git a/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/default.cc
new file mode 100644
index 00000000000..1ca07fe255c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/default.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.1 Class template bernoulli_distribution [rand.dist.bern.bernoulli]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::bernoulli_distribution u;
+ VERIFY( u.p() == 0.5 );
+ VERIFY( u.min() == std::numeric_limits<bool>::min() );
+ VERIFY( u.max() == std::numeric_limits<bool>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/parms.cc
new file mode 100644
index 00000000000..05d4dbedb05
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/parms.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.1 Class template bernoulli_distribution [rand.dist.bern.bernoulli]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::bernoulli_distribution u(0.75);
+ VERIFY( u.p() == 0.75 );
+ VERIFY( u.min() == std::numeric_limits<bool>::min() );
+ VERIFY( u.max() == std::numeric_limits<bool>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..a8a753347ca
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.1 Class template bernoulli_distribution [rand.dist.bern.bernoulli]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::bernoulli_distribution u(0.75), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..5105cbb0d78
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.1 Class template bernoulli_distribution [rand.dist.bern.bernoulli]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::bernoulli_distribution test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/default.cc
new file mode 100644
index 00000000000..62957923360
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/default.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.2 Class template binomial_distribution [rand.dist.bern.bin]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::binomial_distribution<> u;
+ VERIFY( u.t() == 1 );
+ VERIFY( u.p() == 0.5 );
+ VERIFY( u.min() == 0 );
+ VERIFY( u.max() == u.t() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/parms.cc
new file mode 100644
index 00000000000..0a427fe13df
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/parms.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.2 Class template binomial_distribution [rand.dist.bern.bin]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::binomial_distribution<> u(3, 0.75);
+ VERIFY( u.t() == 3 );
+ VERIFY( u.p() == 0.75 );
+ VERIFY( u.min() == 0 );
+ VERIFY( u.max() == u.t() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..8aec5f1d23c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.2 Class template binomial_distribution [rand.dist.bern.bin]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::binomial_distribution<int> u(3, 0.75), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..521d124341a
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.2 Class template binomial_distribution [rand.dist.bern.bin]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::binomial_distribution<int> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/default.cc
new file mode 100644
index 00000000000..67e8d368f9c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/default.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.4 Class template cauchy_distribution [rand.dist.norm.cauchy]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::cauchy_distribution<> u;
+ VERIFY( u.a() == 0.0 );
+ VERIFY( u.b() == 1.0 );
+ typedef std::cauchy_distribution<>::result_type result_type;
+ VERIFY( u.min() == std::numeric_limits<result_type>::min() );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/parms.cc
new file mode 100644
index 00000000000..08d6c6b15a0
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/parms.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.4 Class template cauchy_distribution [rand.dist.norm.cauchy]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::cauchy_distribution<> u(5.0, 2.0);
+ VERIFY( u.a() == 5.0 );
+ VERIFY( u.b() == 2.0 );
+ typedef std::cauchy_distribution<>::result_type result_type;
+ VERIFY( u.min() == std::numeric_limits<result_type>::min() );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..a1fb165ef60
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::cauchy_distribution<double> u(5.0, 2.0), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..192f85c1614
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.4 Class template cauchy_distribution [rand.dist.norm.cauchy]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::cauchy_distribution<double> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/default.cc
new file mode 100644
index 00000000000..3441a207e0d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/default.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.3 Class template chi_squared_distribution [rand.dist.norm.chisq]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::chi_squared_distribution<> u;
+ VERIFY( u.n() == 1 );
+ typedef std::chi_squared_distribution<>::result_type result_type;
+ VERIFY( u.min() == 0.0 );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/parms.cc
new file mode 100644
index 00000000000..f457a9ebc45
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/parms.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.3 Class template chi_squared_distribution [rand.dist.norm.chisq]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::chi_squared_distribution<> u(1.5);
+ VERIFY( u.n() == 1.5 );
+ typedef std::chi_squared_distribution<>::result_type result_type;
+ VERIFY( u.min() == 0.0 );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..927e137f49a
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.3 Class template chi_squared_distribution [rand.dist.norm.chisq]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::chi_squared_distribution<double> u(1.5), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..e110dbdd9ef
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.3 Class template chi_squared_distribution [rand.dist.norm.chisq]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::chi_squared_distribution<double> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/default_random_engine.cc b/libstdc++-v3/testsuite/26_numerics/random/default_random_engine.cc
new file mode 100644
index 00000000000..2886f2dd669
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/default_random_engine.cc
@@ -0,0 +1,48 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2006, 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef]
+// 26.4.5 [10]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::default_random_engine a;
+ a.discard(9999);
+
+ // This is our choice for now.
+ std::minstd_rand0 b;
+ b.discard(9999);
+
+ assert( a() == b() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_copy.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_copy.cc
new file mode 100644
index 00000000000..ab6fb091f0c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_copy.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef std::subtract_with_carry_engine<long, 24, 10, 24>
+ base_engine;
+
+ base_engine b;
+
+ std::discard_block_engine<base_engine, 389, 24> e(b);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_move.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_move.cc
new file mode 100644
index 00000000000..0d8e361a4a5
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_move.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef std::subtract_with_carry_engine<long, 24, 10, 24>
+ base_engine;
+
+ std::discard_block_engine<base_engine, 389, 24>
+ e(std::move(base_engine()));
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/default.cc
new file mode 100644
index 00000000000..cc039b81aac
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/default.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::discard_block_engine
+ <
+ std::subtract_with_carry_engine<long, 24, 10, 24>,
+ 389, 24
+ > e;
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed1.cc
new file mode 100644
index 00000000000..6401cc7ffaf
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed1.cc
@@ -0,0 +1,47 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ unsigned long seed = 2;
+
+ std::discard_block_engine
+ <
+ std::subtract_with_carry_engine<long, 24, 10, 24>,
+ 389, 24
+ > e(seed);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed2.cc
new file mode 100644
index 00000000000..c841d64c9d7
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed2.cc
@@ -0,0 +1,47 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ double seed = 2.0;
+
+ std::discard_block_engine
+ <
+ std::subtract_with_carry_engine<long, 24, 10, 24>,
+ 389, 24
+ > e(seed);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed_seq.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed_seq.cc
new file mode 100644
index 00000000000..182ba1a8833
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed_seq.cc
@@ -0,0 +1,47 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::seed_seq seq;
+
+ std::discard_block_engine
+ <
+ std::subtract_with_carry_engine<long, 24, 10, 24>,
+ 389, 24
+ > e(seq);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/equal.cc
new file mode 100644
index 00000000000..ea906f97112
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/equal.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::discard_block_engine
+ <
+ std::subtract_with_carry_engine<long, 24, 10, 24>,
+ 389, 24
+ > u, v;
+
+ VERIFY( u == v );
+
+ u.discard(100);
+ v.discard(100);
+
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc
new file mode 100644
index 00000000000..84a8d5db70e
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc
@@ -0,0 +1,55 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::discard_block_engine
+ <
+ std::subtract_with_carry_engine<long, 24, 10, 24>,
+ 389, 24
+ > u, v;
+
+ u(); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/requirements/typedefs.cc
new file mode 100644
index 00000000000..67c2d730fad
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/requirements/typedefs.cc
@@ -0,0 +1,39 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 Class template discard_blockl_engine [rand.adapt.disc]
+// 26.4.2.3 Concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::discard_block_engine
+ <
+ std::subtract_with_carry_engine<long, 24, 10, 24>,
+ 389, 24
+ > test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/default.cc
new file mode 100644
index 00000000000..93cd47b0ac3
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/default.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.1 Class template discrete_distribution [rand.dist.samp.discrete]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::discrete_distribution<> u;
+ std::vector<double> probablility = u.probabilities();
+ VERIFY( probablility.size() == 1 );
+ VERIFY( probablility[0] == 1.0 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/initlist.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/initlist.cc
new file mode 100644
index 00000000000..6ddaad98397
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/initlist.cc
@@ -0,0 +1,43 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.1 Class template discrete_distribution [rand.dist.samp.discrete]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::discrete_distribution<> u({0.0, 2.0, 4.0, 3.0, 4.0, 0.0});
+ std::vector<double> probablility = u.probabilities();
+ VERIFY( probablility.size() == 6 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/num_xbound_fun.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/num_xbound_fun.cc
new file mode 100644
index 00000000000..0dbe52a52a9
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/num_xbound_fun.cc
@@ -0,0 +1,67 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.1 Class template discrete_distribution [rand.dist.samp.discrete]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <cmath>
+#include <testsuite_hooks.h>
+
+struct cosine_distribution
+{
+ cosine_distribution(double x0, double lambda)
+ : _M_x0(x0), _M_lambda(lambda)
+ { }
+
+ double
+ operator()(double x)
+ {
+ if (x - _M_x0 < -_M_lambda / 4)
+ return 0.0;
+ else if (x - _M_x0 > _M_lambda / 4)
+ return 0.0;
+ else
+ return std::cos(2 * M_PI * (x - _M_x0) / _M_lambda);
+ }
+
+private:
+ double _M_x0;
+ double _M_lambda;
+};
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ cosine_distribution cd(1.5, 3.0);
+ std::discrete_distribution<> u(21, -10.0, 10.0, cd);
+ std::vector<double> probablility = u.probabilities();
+ VERIFY( probablility.size() == 21 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/range.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/range.cc
new file mode 100644
index 00000000000..cf0f0d9296d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/range.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.1 Class template discrete_distribution [rand.dist.samp.discrete]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::vector<double> wt = {0.5, 1.0, 2.5, 1.5, 0.5};
+ std::discrete_distribution<> u(wt.begin(), wt.end());
+ std::vector<double> probablility = u.probabilities();
+ VERIFY( probablility.size() == 5 );
+ VERIFY( probablility[0] == 0.5 / 6.0 );
+ VERIFY( probablility[2] == 2.5 / 6.0 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..3bd6f6cd12f
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/operators/serialize.cc
@@ -0,0 +1,53 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-05 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.1 Class template discrete_distribution [rand.dist.samp.discrete]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::vector<double> wt = {0.5, 1.0, 2.5, 1.5, 0.5};
+ std::discrete_distribution<int> u(wt.begin(), wt.end()), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..877952aa2cc
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.1 Class template discrete_distribution [rand.dist.samp.discrete]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::discrete_distribution<> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/default.cc
new file mode 100644
index 00000000000..2935bdae4d4
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/default.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.2 Class template exponential_distribution [rand.dist.pois.exp]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::exponential_distribution<> u;
+ VERIFY( u.lambda() == 1.0 );
+ typedef std::exponential_distribution<>::result_type result_type;
+ VERIFY( u.min() == 0 );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/parms.cc
new file mode 100644
index 00000000000..c3b893ced7a
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/parms.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.2 Class template exponential_distribution [rand.dist.pois.exp]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::exponential_distribution<> u(0.5);
+ VERIFY( u.lambda() == 0.5 );
+ typedef std::exponential_distribution<>::result_type result_type;
+ VERIFY( u.min() == 0 );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..9645931f519
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.2 Class template exponential_distribution [rand.dist.pois.exp]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::exponential_distribution<double> u(0.5), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..ce271962f25
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.2 Class template exponential_distribution [rand.dist.pois.exp]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::exponential_distribution<double> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/default.cc
new file mode 100644
index 00000000000..e4378c9bd96
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/default.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.5 Class template extreme_value_distribution [rand.dist.pois.extreme]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::extreme_value_distribution<> u;
+ VERIFY( u.a() == 0.0 );
+ VERIFY( u.b() == 1.0 );
+ typedef std::extreme_value_distribution<>::result_type result_type;
+ VERIFY( u.min() == std::numeric_limits<result_type>::min() );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/parms.cc
new file mode 100644
index 00000000000..1e54492b124
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/parms.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.5 Class template extreme_value_distribution [rand.dist.pois.extreme]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::extreme_value_distribution<> u(5.0, 2.0);
+ VERIFY( u.a() == 5.0 );
+ VERIFY( u.b() == 2.0 );
+ typedef std::extreme_value_distribution<>::result_type result_type;
+ VERIFY( u.min() == std::numeric_limits<result_type>::min() );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..c07cdfc1ab8
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.5 Class template extreme_value_distribution [rand.dist.pois.extreme]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::extreme_value_distribution<double> u, v(5.0, 2.0);
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..e87436f2bec
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.5 Class template extreme_value_distribution [rand.dist.pois.extreme]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::extreme_value_distribution<double> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/default.cc
new file mode 100644
index 00000000000..e7accb3a378
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/default.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.5 Class template fisher_f_distribution [rand.dist.norm.f]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::fisher_f_distribution<> u;
+ VERIFY( u.m() == 1.0 );
+ VERIFY( u.n() == 1.0 );
+ typedef std::fisher_f_distribution<>::result_type result_type;
+ VERIFY( u.min() == 0.0 );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/parms.cc
new file mode 100644
index 00000000000..5c02b82d444
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/parms.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.5 Class template fisher_f_distribution [rand.dist.norm.f]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::fisher_f_distribution<> u(2.0, 3.0);
+ VERIFY( u.m() == 2.0 );
+ VERIFY( u.n() == 3.0 );
+ typedef std::fisher_f_distribution<>::result_type result_type;
+ VERIFY( u.min() == 0.0 );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..6cb024972c5
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.5 Class template fisher_f_distribution [rand.dist.norm.f]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::fisher_f_distribution<double> u(2.0, 3.0), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..207dfd58ac9
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.5 Class template fisher_f_distribution [rand.dist.norm.f]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::fisher_f_distribution<double> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/default.cc
new file mode 100644
index 00000000000..74be9d18960
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/default.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.3 Class template gamma_distribution [rand.dist.pois.gamma]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::gamma_distribution<> u;
+ VERIFY( u.alpha() == 1.0 );
+ VERIFY( u.beta() == 1.0 );
+ VERIFY( u.min() == 0.0 );
+ typedef std::gamma_distribution<>::result_type result_type;
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/parms.cc
new file mode 100644
index 00000000000..1dd7a76a5dc
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/parms.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.3 Class template gamma_distribution [rand.dist.pois.gamma]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::gamma_distribution<> u(1.5, 3.0);
+ VERIFY( u.alpha() == 1.5 );
+ VERIFY( u.beta() == 3.0 );
+ VERIFY( u.min() == 0.0 );
+ typedef std::gamma_distribution<>::result_type result_type;
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..b99e0c24e42
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.3 Class template gamma_distribution [rand.dist.pois.gamma]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::gamma_distribution<double> u(1.5, 3.0), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..b3c6b4eeafa
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.3 Class template gamma_distribution [rand.dist.pois.gamma]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::gamma_distribution<double> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/default.cc
new file mode 100644
index 00000000000..e248f7f0ce6
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/default.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.3 Class template geometric_distribution [rand.dist.bern.geo]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::geometric_distribution<> u;
+ VERIFY( u.p() == 0.5 );
+ VERIFY( u.min() == 0 );
+ typedef std::geometric_distribution<>::result_type result_type;
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/parms.cc
new file mode 100644
index 00000000000..aa158a32ac1
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/parms.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.3 Class template geometric_distribution [rand.dist.bern.geo]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::geometric_distribution<> u(0.75);
+ VERIFY( u.p() == 0.75 );
+ VERIFY( u.min() == 0 );
+ typedef std::geometric_distribution<>::result_type result_type;
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..e2fbdaa29a4
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.3 Class template geometric_distribution [rand.dist.bern.geom]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::geometric_distribution<int> u(0.75), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..7cac29a40e2
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.3 Class template geometric_distribution [rand.dist.bern.geom]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::geometric_distribution<int> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_copy.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_copy.cc
new file mode 100644
index 00000000000..efaa94b2f64
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_copy.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
+ base_engine;
+
+ base_engine b;
+
+ std::independent_bits_engine<base_engine, 48, unsigned long> e(b);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_move.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_move.cc
new file mode 100644
index 00000000000..8adcecd25ef
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_move.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
+ base_engine;
+
+ std::independent_bits_engine<base_engine, 48, unsigned long>
+ e(std::move(base_engine()));
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/default.cc
new file mode 100644
index 00000000000..2ccd4e8d557
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/default.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::independent_bits_engine
+ <
+ std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>,
+ 48,
+ unsigned long
+ > e;
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed1.cc
new file mode 100644
index 00000000000..e774b760c9c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed1.cc
@@ -0,0 +1,48 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ unsigned long seed = 2;
+
+ std::independent_bits_engine
+ <
+ std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>,
+ 48,
+ unsigned long
+ > e(seed);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed2.cc
new file mode 100644
index 00000000000..e4362d6165d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed2.cc
@@ -0,0 +1,48 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ double seed = 2.0;
+
+ std::independent_bits_engine
+ <
+ std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>,
+ 48,
+ unsigned long
+ > e(seed);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed_seq.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed_seq.cc
new file mode 100644
index 00000000000..628af20b96f
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed_seq.cc
@@ -0,0 +1,48 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::seed_seq seq;
+
+ std::independent_bits_engine
+ <
+ std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>,
+ 48,
+ unsigned long
+ > e(seq);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/equal.cc
new file mode 100644
index 00000000000..6147cf0d5ac
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/equal.cc
@@ -0,0 +1,50 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::independent_bits_engine
+ <std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>,
+ 48, unsigned long> u, v;
+
+ VERIFY( u == v );
+
+ u.discard(100);
+ v.discard(100);
+
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc
new file mode 100644
index 00000000000..a92553e10cd
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc
@@ -0,0 +1,53 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::independent_bits_engine
+ <std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>,
+ 48, unsigned long> u, v;
+
+ u(); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/requirements/typedefs.cc
new file mode 100644
index 00000000000..f268e9ad808
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/requirements/typedefs.cc
@@ -0,0 +1,42 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits]
+// 26.4.2.3 Concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::independent_bits_engine
+ <
+ std::subtract_with_carry_engine
+ <
+ uint_fast64_t, 48, 5, 12
+ >,
+ 48, unsigned long
+ > test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/knuth_b.cc b/libstdc++-v3/testsuite/26_numerics/random/knuth_b.cc
new file mode 100644
index 00000000000..5f835769efb
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/knuth_b.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2006, 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef]
+// 26.4.5 [9]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::knuth_b a;
+ a.discard(9999);
+
+ VERIFY( a() == 1112339016 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/default.cc
new file mode 100644
index 00000000000..1136785e9a3
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/default.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::linear_congruential_engine<unsigned long, 48271, 0, 2147483647> x;
+ VERIFY( x.min() == 1 );
+ VERIFY( x.max() == 2147483647-1 );
+ VERIFY( x() == 48271 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed1.cc
new file mode 100644
index 00000000000..9d2e21b54c7
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed1.cc
@@ -0,0 +1,40 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ unsigned long seed = 2;
+ std::linear_congruential_engine<unsigned long, 48271, 0, 2147483647> x(seed);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed2.cc
new file mode 100644
index 00000000000..5f446773ecc
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed2.cc
@@ -0,0 +1,40 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ double seed = 2.0;
+ std::linear_congruential_engine<unsigned long, 48271, 0, 2147483647> x(seed);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/equal.cc
new file mode 100644
index 00000000000..02f1f5a9708
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/equal.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::minstd_rand0 a;
+ std::minstd_rand0 b;
+ std::minstd_rand0 c(120);
+
+ VERIFY( a == b );
+ VERIFY( !(a == c) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc
new file mode 100644
index 00000000000..6256cadc68d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc
@@ -0,0 +1,51 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::minstd_rand0 a;
+ std::minstd_rand0 b;
+
+ a(); // advance
+ str << a;
+ VERIFY( !(a == b) );
+
+ str >> b;
+ VERIFY( a == b );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/non_uint_neg.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/non_uint_neg.cc
new file mode 100644
index 00000000000..4c83a97adfd
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/non_uint_neg.cc
@@ -0,0 +1,33 @@
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// { dg-do compile }
+// { dg-options "-std=c++0x -D_GLIBCXX_CONCEPT_CHECKS" }
+// { dg-error "not a valid type" "" { target *-*-* } 32 }
+// { dg-error "invalid type" "" { target *-*-* } 32 }
+
+// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+
+std::linear_congruential_engine<double, 48271, 0, 2147483647> x;
+
diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/typedefs.cc
new file mode 100644
index 00000000000..5c9b8ad6abb
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::linear_congruential_engine<unsigned long, 2, 0, 4> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/default.cc
new file mode 100644
index 00000000000..4fe1dda5213
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/default.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.2 Class template lognormal_distribution [rand.dist.norm.lognormal]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::lognormal_distribution<> u;
+ VERIFY( u.m() == 0.0 );
+ VERIFY( u.s() == 1.0 );
+ typedef std::lognormal_distribution<>::result_type result_type;
+ VERIFY( u.min() == 0.0 );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/parms.cc
new file mode 100644
index 00000000000..42fe3ac3816
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/parms.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.2 Class template lognormal_distribution [rand.dist.norm.lognormal]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::lognormal_distribution<> u(5.0, 2.0);
+ VERIFY( u.m() == 5.0 );
+ VERIFY( u.s() == 2.0 );
+ typedef std::lognormal_distribution<>::result_type result_type;
+ VERIFY( u.min() == 0.0 );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..3626cfbb424
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.2 Class template lognormal_distribution [rand.dist.norm.lognormal]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::lognormal_distribution<double> u(5.0, 2.0), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..c1260aa604a
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.2 Class template lognormal_distribution [rand.dist.norm.lognormal]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::lognormal_distribution<double> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/default.cc
new file mode 100644
index 00000000000..e335b82217b
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/default.cc
@@ -0,0 +1,51 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+ typedef unsigned long value_type;
+
+ std::mersenne_twister_engine<
+ value_type, 32, 624, 397, 31,
+ 0x9908b0dful, 11,
+ 0xfffffffful, 7,
+ 0x9d2c5680ul, 15,
+ 0xefc60000ul, 18, 1812433253ul> x;
+
+ VERIFY( x.min() == 0 );
+ // XXX VERIFY( x.max() == 4294967295ul);
+ VERIFY( x() == 3499211612ul );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed1.cc
new file mode 100644
index 00000000000..a5e0489fefa
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed1.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ unsigned long seed = 2;
+ std::mersenne_twister_engine<
+ unsigned long, 32, 624, 397, 31,
+ 0x9908b0dful, 11,
+ 0xfffffffful, 7,
+ 0x9d2c5680ul, 15,
+ 0xefc60000ul, 18, 1812433253ul> x(seed);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed2.cc
new file mode 100644
index 00000000000..954f27360f4
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed2.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ double seed = 2.0;
+ std::mersenne_twister_engine<
+ unsigned long, 32, 624, 397, 31,
+ 0x9908b0dful, 11,
+ 0xfffffffful, 7,
+ 0x9d2c5680ul, 15,
+ 0xefc60000ul, 18, 1812433253ul> x(seed);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/equal.cc
new file mode 100644
index 00000000000..1e7b4d9941c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/equal.cc
@@ -0,0 +1,53 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::mersenne_twister_engine<
+ unsigned long, 32, 624, 397, 31,
+ 0x9908b0dful, 11,
+ 0xfffffffful, 7,
+ 0x9d2c5680ul, 15,
+ 0xefc60000ul, 18, 1812433253ul> u, v;
+
+ VERIFY( u == v );
+
+ u.discard(100);
+ v.discard(100);
+
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc
new file mode 100644
index 00000000000..90f51d6cbf2
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc
@@ -0,0 +1,56 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <sstream>
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::mersenne_twister_engine<
+ unsigned long, 32, 624, 397, 31,
+ 0x9908b0dful, 11,
+ 0xfffffffful, 7,
+ 0x9d2c5680ul, 15,
+ 0xefc60000ul, 18, 1812433253ul> u, v;
+
+ u(); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/requirements/typedefs.cc
new file mode 100644
index 00000000000..e94bd08a352
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/requirements/typedefs.cc
@@ -0,0 +1,40 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::mersenne_twister_engine<unsigned long,
+ 32, 624, 397, 31,
+ 0x9908b0df, 11,
+ 0xfffffffful, 7,
+ 0x9d2c5680, 15,
+ 0xefc60000, 18, 1812433253ul> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/minstd_rand.cc b/libstdc++-v3/testsuite/26_numerics/random/minstd_rand.cc
new file mode 100644
index 00000000000..c8118a3bedf
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/minstd_rand.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2006, 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.5 Engines with predefined parameters
+// 26.4.5 [2]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::minstd_rand a;
+ a.discard(9999);
+
+ VERIFY( a() == 399268537 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/minstd_rand0.cc b/libstdc++-v3/testsuite/26_numerics/random/minstd_rand0.cc
new file mode 100644
index 00000000000..045f1f97b5e
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/minstd_rand0.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef]
+// 26.4.5 [1]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::minstd_rand0 a;
+ a.discard(9999);
+
+ VERIFY( a() == 1043618065 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/mt19937.cc b/libstdc++-v3/testsuite/26_numerics/random/mt19937.cc
new file mode 100644
index 00000000000..81e2f086efb
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/mt19937.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2006, 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef]
+// 26.4.5 [3]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::mt19937 a;
+ a.discard(9999);
+
+ VERIFY( a() == 4123659995ul );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/mt19937_64.cc b/libstdc++-v3/testsuite/26_numerics/random/mt19937_64.cc
new file mode 100644
index 00000000000..2ec8a54ce5e
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/mt19937_64.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2006, 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef]
+// 26.4.5 [4]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::mt19937_64 a;
+ a.discard(9999);
+
+ VERIFY( a() == 9981545732273789042ul );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/default.cc
new file mode 100644
index 00000000000..280a9d7833e
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/default.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.4 Class template negative_binomial_distribution [rand.dist.bern.negbin]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::negative_binomial_distribution<> u;
+ VERIFY( u.k() == 1 );
+ VERIFY( u.p() == 0.5 );
+ typedef std::negative_binomial_distribution<>::result_type result_type;
+ VERIFY( u.min() == 0 );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/parms.cc
new file mode 100644
index 00000000000..0c2f66d5d95
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/parms.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.4 Class template negative_binomial_distribution [rand.dist.bern.negbin]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::negative_binomial_distribution<> u(3, 0.75);
+ VERIFY( u.k() == 3 );
+ VERIFY( u.p() == 0.75 );
+ typedef std::negative_binomial_distribution<>::result_type result_type;
+ VERIFY( u.min() == 0 );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..1817d731afe
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.4 Class template negative_binomial_distribution [rand.dist.bern.negbin]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::negative_binomial_distribution<int> u(3, 0.75), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..b5888c426c8
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.2.4 Class template negative_binomial_distribution [rand.dist.bern.negbin]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::negative_binomial_distribution<int> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/default.cc
new file mode 100644
index 00000000000..1c6ee51a172
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/default.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.1 Class template normal_distribution [rand.dist.norm.normal]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::normal_distribution<> u;
+ VERIFY( u.mean() == 0.0 );
+ VERIFY( u.stddev() == 1.0 );
+ typedef std::normal_distribution<>::result_type result_type;
+ VERIFY( u.min() == std::numeric_limits<result_type>::min() );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/parms.cc
new file mode 100644
index 00000000000..41bf9c44ffc
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/parms.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.1 Class template normal_distribution [rand.dist.norm.normal]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::normal_distribution<> u(5.0, 2.0);
+ VERIFY( u.mean() == 5.0 );
+ VERIFY( u.stddev() == 2.0 );
+ typedef std::normal_distribution<>::result_type result_type;
+ VERIFY( u.min() == std::numeric_limits<result_type>::min() );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..fdf90ca525d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.1 Class template normal_distribution [rand.dist.norm.normal]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::normal_distribution<double> u(5.0, 2.0), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..d22ad223a54
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.1 Class template normal_distribution [rand.dist.norm.normal]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::normal_distribution<double> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/default.cc
new file mode 100644
index 00000000000..f5e9506d0f4
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/default.cc
@@ -0,0 +1,48 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::piecewise_constant_distribution<> u;
+ std::vector<double> interval = u.intervals();
+ std::vector<double> density = u.densities();
+ VERIFY( interval.size() == 2 );
+ VERIFY( interval[0] == 0.0 );
+ VERIFY( interval[1] == 1.0 );
+ VERIFY( density.size() == 1 );
+ VERIFY( density[0] == 1.0 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/initlist_fun.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/initlist_fun.cc
new file mode 100644
index 00000000000..22bf5b2c438
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/initlist_fun.cc
@@ -0,0 +1,71 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <cmath>
+#include <testsuite_hooks.h>
+
+struct cosine_distribution
+{
+ cosine_distribution(double x0, double lambda)
+ : _M_x0(x0), _M_lambda(lambda)
+ { }
+
+ double
+ operator()(double x)
+ {
+ if (x - _M_x0 < -_M_lambda / 4)
+ return 0.0;
+ else if (x - _M_x0 > _M_lambda / 4)
+ return 0.0;
+ else
+ return std::cos(2 * M_PI * (x - _M_x0) / _M_lambda);
+ }
+
+private:
+ double _M_x0;
+ double _M_lambda;
+};
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ cosine_distribution cd(1.5, 3.0);
+ std::piecewise_constant_distribution<> u({-10.0, -8.0, -6.0, -4.0, -2.0,
+ 0.0, 2.0, 4.0, 6.0, 8.0, 10.0},
+ cd);
+ std::vector<double> interval = u.intervals();
+ std::vector<double> density = u.densities();
+ VERIFY( interval.size() == 11 );
+ VERIFY( density.size() == 10 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/num_xbound_fun.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/num_xbound_fun.cc
new file mode 100644
index 00000000000..ff900a64049
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/num_xbound_fun.cc
@@ -0,0 +1,69 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <cmath>
+#include <testsuite_hooks.h>
+
+struct cosine_distribution
+{
+ cosine_distribution(double x0, double lambda)
+ : _M_x0(x0), _M_lambda(lambda)
+ { }
+
+ double
+ operator()(double x)
+ {
+ if (x - _M_x0 < -_M_lambda / 4)
+ return 0.0;
+ else if (x - _M_x0 > _M_lambda / 4)
+ return 0.0;
+ else
+ return std::cos(2 * M_PI * (x - _M_x0) / _M_lambda);
+ }
+
+private:
+ double _M_x0;
+ double _M_lambda;
+};
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ cosine_distribution cd(1.5, 3.0);
+ std::piecewise_constant_distribution<> u(21, -10.0, 10.0, cd);
+ std::vector<double> interval = u.intervals();
+ std::vector<double> density = u.densities();
+ VERIFY( interval.size() == 22 );
+ VERIFY( density.size() == 21 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/range.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/range.cc
new file mode 100644
index 00000000000..5e2ee1024fa
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/range.cc
@@ -0,0 +1,51 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::vector<double> x = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
+ std::vector<double> wt = {0.5, 1.0, 2.5, 1.5, 0.5};
+ std::piecewise_constant_distribution<> u(x.begin(), x.end(), wt.begin());
+ std::vector<double> interval = u.intervals();
+ std::vector<double> density = u.densities();
+ VERIFY( interval.size() == 6 );
+ VERIFY( interval[0] == 0.0 );
+ VERIFY( interval[5] == 5.0 );
+ VERIFY( density.size() == 5 );
+ VERIFY( density[0] == 0.5 / 6.0 );
+ VERIFY( density[2] == 2.5 / 6.0 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..28b2fb3333d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/operators/serialize.cc
@@ -0,0 +1,55 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-05 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::vector<double> x = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
+ std::vector<double> wt = {0.5, 1.0, 2.5, 1.5, 0.5};
+ std::piecewise_constant_distribution<double>
+ u(x.begin(), x.end(), wt.begin()), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..523261e488c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::piecewise_constant_distribution<> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/default.cc
new file mode 100644
index 00000000000..41c5e484a35
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/default.cc
@@ -0,0 +1,49 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::piecewise_linear_distribution<> u;
+ std::vector<double> interval = u.intervals();
+ std::vector<double> density = u.densities();
+ VERIFY( interval.size() == 2 );
+ VERIFY( interval[0] == 0.0 );
+ VERIFY( interval[1] == 1.0 );
+ VERIFY( density.size() == 2 );
+ VERIFY( density[0] == 1.0 );
+ VERIFY( density[1] == 1.0 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/initlist_fun.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/initlist_fun.cc
new file mode 100644
index 00000000000..91db760cef7
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/initlist_fun.cc
@@ -0,0 +1,71 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <cmath>
+#include <testsuite_hooks.h>
+
+struct cosine_distribution
+{
+ cosine_distribution(double x0, double lambda)
+ : _M_x0(x0), _M_lambda(lambda)
+ { }
+
+ double
+ operator()(double x)
+ {
+ if (x - _M_x0 < -_M_lambda / 4)
+ return 0.0;
+ else if (x - _M_x0 > _M_lambda / 4)
+ return 0.0;
+ else
+ return std::cos(2 * M_PI * (x - _M_x0) / _M_lambda);
+ }
+
+private:
+ double _M_x0;
+ double _M_lambda;
+};
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ cosine_distribution cd(1.5, 3.0);
+ std::piecewise_linear_distribution<> u({-10.0, -8.0, -6.0, -4.0, -2.0,
+ 0.0, 2.0, 4.0, 6.0, 8.0, 10.0},
+ cd);
+ std::vector<double> interval = u.intervals();
+ std::vector<double> density = u.densities();
+ VERIFY( interval.size() == 11 );
+ VERIFY( density.size() == 11 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/num_xbound_fun.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/num_xbound_fun.cc
new file mode 100644
index 00000000000..187601b8a41
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/num_xbound_fun.cc
@@ -0,0 +1,69 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <cmath>
+#include <testsuite_hooks.h>
+
+struct cosine_distribution
+{
+ cosine_distribution(double x0, double lambda)
+ : _M_x0(x0), _M_lambda(lambda)
+ { }
+
+ double
+ operator()(double x)
+ {
+ if (x - _M_x0 < -_M_lambda / 4)
+ return 0.0;
+ else if (x - _M_x0 > _M_lambda / 4)
+ return 0.0;
+ else
+ return std::cos(2 * M_PI * (x - _M_x0) / _M_lambda);
+ }
+
+private:
+ double _M_x0;
+ double _M_lambda;
+};
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ cosine_distribution cd(1.5, 3.0);
+ std::piecewise_linear_distribution<> u(21, -10.0, 10.0, cd);
+ std::vector<double> interval = u.intervals();
+ std::vector<double> density = u.densities();
+ VERIFY( interval.size() == 22 );
+ VERIFY( density.size() == 22 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/range.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/range.cc
new file mode 100644
index 00000000000..1e0dbbc824a
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/range.cc
@@ -0,0 +1,51 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::vector<double> x = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
+ std::vector<double> wt = {0.0, 1.0, 2.5, 1.5, 3.5, 0.0};
+ std::piecewise_linear_distribution<> u(x.begin(), x.end(), wt.begin());
+ std::vector<double> interval = u.intervals();
+ std::vector<double> density = u.densities();
+ VERIFY( interval.size() == 6 );
+ VERIFY( interval[0] == 0.0 );
+ VERIFY( interval[5] == 5.0 );
+ VERIFY( density.size() == 6 );
+ VERIFY( density[0] == 0.0 );
+ VERIFY( density[4] == 3.5 / 8.5 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..c38d47a5d31
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/operators/serialize.cc
@@ -0,0 +1,55 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-05 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::vector<double> x = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
+ std::vector<double> wt = {0.0, 1.0, 2.5, 1.5, 0.5, 0.0};
+ std::piecewise_linear_distribution<double>
+ u(x.begin(), x.end(), wt.begin()), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..71f80df8024
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.5.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::piecewise_linear_distribution<> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/default.cc
new file mode 100644
index 00000000000..bf6c7532877
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/default.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.1 Class template poisson_distribution [rand.dist.pois.poisson]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::poisson_distribution<> u;
+ VERIFY( u.mean() == 1.0 );
+ VERIFY( u.min() == 0 );
+ typedef std::poisson_distribution<>::result_type result_type;
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/parms.cc
new file mode 100644
index 00000000000..b498a2e58d3
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/parms.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.1 Class template poisson_distribution [rand.dist.pois.poisson]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::poisson_distribution<> u(5.0);
+ VERIFY( u.mean() == 5.0 );
+ VERIFY( u.min() == 0 );
+ typedef std::poisson_distribution<>::result_type result_type;
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..79511024885
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.1 Class template poisson_distribution [rand.dist.pois.poisson]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::poisson_distribution<int> u(5.0), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..125a9067acc
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.1 Class template poisson_distribution [rand.dist.pois.poisson]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::poisson_distribution<int> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/default.cc
new file mode 100644
index 00000000000..e162038a90b
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/default.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.6 class random_device [rand.device]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::random_device x;
+
+ VERIFY( x.min() == std::numeric_limits<std::random_device::result_type>::min() );
+ VERIFY( x.max() == std::numeric_limits<std::random_device::result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/token.cc b/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/token.cc
new file mode 100644
index 00000000000..ec5e16f004b
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/token.cc
@@ -0,0 +1,48 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.6 class random_device [rand.device]
+// 26.4.6 [3]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+#ifdef _GLIBCXX_USE_RANDOM_TR1
+ std::random_device x("/dev/random");
+#else
+ std::random_device x("0");
+#endif
+
+ VERIFY( x.min() == std::numeric_limits<std::random_device::result_type>::min() );
+ VERIFY( x.max() == std::numeric_limits<std::random_device::result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/random_device/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/random_device/requirements/typedefs.cc
new file mode 100644
index 00000000000..0ebf1aa551c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/random_device/requirements/typedefs.cc
@@ -0,0 +1,34 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.6 class random_device [rand.device]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::random_device test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/ranlux24.cc b/libstdc++-v3/testsuite/26_numerics/random/ranlux24.cc
new file mode 100644
index 00000000000..7b20eb36c3b
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/ranlux24.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef]
+// 26.4.5 [7]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::ranlux24 a;
+ a.discard(9999);
+
+ VERIFY( a() == 9901578ul );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/ranlux24_base.cc b/libstdc++-v3/testsuite/26_numerics/random/ranlux24_base.cc
new file mode 100644
index 00000000000..5298858f95e
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/ranlux24_base.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef]
+// 26.4.5 [5]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::ranlux24_base a;
+ a.discard(9999);
+
+ VERIFY( a() == 7937952ul );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/ranlux48.cc b/libstdc++-v3/testsuite/26_numerics/random/ranlux48.cc
new file mode 100644
index 00000000000..57b07205b94
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/ranlux48.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef]
+// 26.4.5 [8]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::ranlux48 a;
+ a.discard(9999);
+
+ VERIFY( a() == 249142670248501ull );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/ranlux48_base.cc b/libstdc++-v3/testsuite/26_numerics/random/ranlux48_base.cc
new file mode 100644
index 00000000000..c5b1ef64c0d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/ranlux48_base.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef]
+// 26.4.5 [6]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::ranlux48_base a;
+ a.discard(9999);
+
+ VERIFY( a() == 61839128582725ull );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/default.cc
new file mode 100644
index 00000000000..7bbfdc30420
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/default.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-05 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.7.1 Class seed_seq [rand.util.seedseq]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::seed_seq seq;
+
+ std::vector<unsigned> foo(10000);
+ seq.generate(foo.begin(), foo.end());
+
+ VERIFY( seq.size() == 0 );
+ //VERIFY();
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/initlist.cc b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/initlist.cc
new file mode 100644
index 00000000000..4bfa217c181
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/initlist.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2009-02-13 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.7.1 Class seed_seq [rand.util.seedseq]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::seed_seq seq({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
+
+ std::vector<unsigned> foo(10000);
+ seq.generate(foo.begin(), foo.end());
+
+ VERIFY( seq.size() == 10 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/range.cc b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/range.cc
new file mode 100644
index 00000000000..c5eda5dbcc9
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/range.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-05 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.7.1 Class seed_seq [rand.util.seedseq]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ unsigned in[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+ std::seed_seq seq(in, in + 10);
+
+ std::vector<unsigned> foo(10000);
+ seq.generate(foo.begin(), foo.end());
+
+ VERIFY( seq.size() == 10 );
+ //VERIFY();
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/seed_seq/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/requirements/typedefs.cc
new file mode 100644
index 00000000000..90455607149
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/requirements/typedefs.cc
@@ -0,0 +1,34 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-05 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.7.1 Class seed_seq [rand.util.seedseq]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::seed_seq test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_copy.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_copy.cc
new file mode 100644
index 00000000000..a2659dd468c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_copy.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef std::linear_congruential_engine
+ <uint_fast32_t, 16807UL, 0UL, 2147483647UL> base_engine;
+
+ base_engine b;
+
+ std::shuffle_order_engine<base_engine, 256> e(b);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_move.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_move.cc
new file mode 100644
index 00000000000..4e8c7af3d31
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_move.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef std::linear_congruential_engine
+ <uint_fast32_t, 16807UL, 0UL, 2147483647UL> base_engine;
+
+ std::shuffle_order_engine<base_engine, 256>
+ e(std::move(base_engine()));
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/default.cc
new file mode 100644
index 00000000000..a33a6551c93
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/default.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::shuffle_order_engine
+ <
+ std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>,
+ 256
+ > e;
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed1.cc
new file mode 100644
index 00000000000..0df9c55cbf3
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed1.cc
@@ -0,0 +1,47 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ unsigned long seed = 2;
+
+ std::shuffle_order_engine
+ <
+ std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>,
+ 256
+ > e(seed);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed2.cc
new file mode 100644
index 00000000000..c492d0a30a3
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed2.cc
@@ -0,0 +1,47 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ double seed = 2.0;
+
+ std::shuffle_order_engine
+ <
+ std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>,
+ 256
+ > e(seed);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq.cc
new file mode 100644
index 00000000000..80c425b3dcf
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq.cc
@@ -0,0 +1,47 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::seed_seq seq;
+
+ std::shuffle_order_engine
+ <
+ std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>,
+ 256
+ > e(seq);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/equal.cc
new file mode 100644
index 00000000000..3b5cebb5853
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/equal.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::shuffle_order_engine
+ <
+ std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>,
+ 256
+ > u, v;
+
+ VERIFY( u == v );
+
+ u.discard(100);
+ v.discard(100);
+
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc
new file mode 100644
index 00000000000..afaa4051468
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc
@@ -0,0 +1,55 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.1 class template discard_block_engine [rand.adapt.disc]
+// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::shuffle_order_engine
+ <
+ std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>,
+ 256
+ > u, v;
+
+ u(); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/requirements/typedefs.cc
new file mode 100644
index 00000000000..605a10089ce
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/requirements/typedefs.cc
@@ -0,0 +1,41 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf]
+// 26.4.2.3 Concept RandomNumberEngineAdaptor [rand.concept.adapt]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::shuffle_order_engine
+ <
+ std::linear_congruential_engine
+ <
+ uint_fast32_t,16807UL, 0UL, 2147483647UL
+ >,
+ 256
+ > test_type;
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/default.cc
new file mode 100644
index 00000000000..5f0169b739d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/default.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.6 Class template student_t_distribution [rand.dist.norm.t]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::student_t_distribution<> u;
+ VERIFY( u.n() == 1.0 );
+ typedef std::student_t_distribution<>::result_type result_type;
+ VERIFY( u.min() == std::numeric_limits<result_type>::min() );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/parms.cc
new file mode 100644
index 00000000000..4d6aa6149e5
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/parms.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.6 Class template student_t_distribution [rand.dist.norm.t]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::student_t_distribution<> u(1.5);
+ VERIFY( u.n() == 1.5 );
+ typedef std::student_t_distribution<>::result_type result_type;
+ VERIFY( u.min() == std::numeric_limits<result_type>::min() );
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..ab3a9bb6112
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.6 Class template student_t_distribution [rand.dist.norm.t]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::student_t_distribution<double> u(1.5), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..3380873cd63
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.4.6 Class template student_t_distribution [rand.dist.norm.t]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::student_t_distribution<double> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/default.cc
new file mode 100644
index 00000000000..8d841074f5b
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/default.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.3 Class template subtract_with_carry_engine [rand.eng.sub]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::subtract_with_carry_engine<unsigned long, 24, 10, 24> x;
+ VERIFY( x.min() == 0 );
+ VERIFY( x.max() == ((1UL << 24) - 1) );
+ VERIFY( x() == 15039276 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed1.cc
new file mode 100644
index 00000000000..e26261a1219
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed1.cc
@@ -0,0 +1,40 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.3 Class template subtract_with_carry_engine [rand.eng.sub]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ unsigned long seed = 2;
+ std::subtract_with_carry_engine<unsigned long, 24, 10, 24> x(seed);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed2.cc
new file mode 100644
index 00000000000..8b96c16b43d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed2.cc
@@ -0,0 +1,40 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.3 Class template subtract_with_carry_engine [rand.eng.sub]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ double seed = 2.0;
+ std::subtract_with_carry_engine<unsigned long, 24, 10, 24> x(seed);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/equal.cc
new file mode 100644
index 00000000000..9dbed3c4653
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/equal.cc
@@ -0,0 +1,49 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.3 Class template subtract_with_carry_engine [rand.eng.sub]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::subtract_with_carry_engine<unsigned long, 24, 10, 24> u;
+ std::subtract_with_carry_engine<unsigned long, 24, 10, 24> v;
+
+ VERIFY( u == v );
+
+ u.discard(100);
+ v.discard(100);
+
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc
new file mode 100644
index 00000000000..e6705e43aef
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.3 Class template subtract_with_carry_engine [rand.eng.sub]
+// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng]
+
+#include <sstream>
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::subtract_with_carry_engine<unsigned long, 24, 10, 24> u;
+ std::subtract_with_carry_engine<unsigned long, 24, 10, 24> v;
+
+ u(); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/requirements/typedefs.cc
new file mode 100644
index 00000000000..2cd922f1c60
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/requirements/typedefs.cc
@@ -0,0 +1,36 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.3.3 Class template subtract_with_carry_engine [rand.eng.sub]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::subtract_with_carry_engine<unsigned long, 24, 10, 24>
+ test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc
new file mode 100644
index 00000000000..db5c653e923
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.1.1 Class template uniform_int_distribution [rand.dist.uni.int]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::uniform_int_distribution<int> u;
+ VERIFY( u.a() == 0 );
+ VERIFY( u.b() == 9 );
+ VERIFY( u.min() == 0 );
+ VERIFY( u.max() == 9 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms.cc
new file mode 100644
index 00000000000..3e4f4858d98
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.1.1 Class template uniform_int_distribution [rand.dist_uni]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::uniform_int_distribution<int> u(1, 20);
+ VERIFY( u.a() == 1 );
+ VERIFY( u.b() == 20 );
+ VERIFY( u.min() == 1 );
+ VERIFY( u.max() == 20 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms_neg.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms_neg.cc
new file mode 100644
index 00000000000..129cc25d0c6
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms_neg.cc
@@ -0,0 +1,41 @@
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-options "-std=c++0x -D_GLIBCXX_DEBUG" }
+
+// 26.4.8.1.1 Class template uniform_int_distribution [rand.dist_uni]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::uniform_int_distribution<int> u(20, 1);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..486bdb4ea9b
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.1.1 Class template uniform_int_distribution [rand.dist_uni]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::uniform_int_distribution<int> u(1, 20), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..2074c12d03a
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.1.1 Class template uniform_int_distribution [rand.dist_uni]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::uniform_int_distribution<int> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/default.cc
new file mode 100644
index 00000000000..944fe827751
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/default.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.1.1 Class template uniform_real_distribution [rand.dist.uni.real]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::uniform_real_distribution<double> u;
+ VERIFY( u.a() == 0.0 );
+ VERIFY( u.b() == 1.0 );
+ VERIFY( u.min() == 0.0 );
+ VERIFY( u.max() == 1.0 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms.cc
new file mode 100644
index 00000000000..cbfbd41b8b1
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.1.1 Class template uniform_real_distribution [rand.dist_uni]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::uniform_real_distribution<double> u(-5.0, 5.0);
+ VERIFY( u.a() == -5.0 );
+ VERIFY( u.b() == 5.0 );
+ VERIFY( u.min() == -5.0 );
+ VERIFY( u.max() == 5.0 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms_neg.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms_neg.cc
new file mode 100644
index 00000000000..930f9de1464
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms_neg.cc
@@ -0,0 +1,41 @@
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// { dg-do run { xfail *-*-* } }
+// { dg-options "-std=c++0x -D_GLIBCXX_DEBUG" }
+
+// 26.4.8.1.1 Class template uniform_real_distribution [rand.dist_uni]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::uniform_real_distribution<double> u(5.0, 0.0);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..3fbc584307d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.1.2 Class template uniform_real_distribution [rand.dist.uni.real]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::uniform_real_distribution<double> u(-5.0, 5.0), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..696e20b601a
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.1.2 Class template uniform_real_distribution [rand.dist.uni.real]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::uniform_real_distribution<double> test_type;
+
+ typedef test_type::result_type result_type;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/default.cc
new file mode 100644
index 00000000000..6867c117a62
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/default.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.4 Class template weibull_distribution [rand.dist.pois.weibull]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::weibull_distribution<> u;
+ VERIFY( u.a() == 1.0 );
+ VERIFY( u.b() == 1.0 );
+ VERIFY( u.min() == 0.0 );
+ typedef std::weibull_distribution<>::result_type result_type;
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/parms.cc
new file mode 100644
index 00000000000..3eec8c6489d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/parms.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.4 Class template weibull_distribution [rand.dist.pois.weibull]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::weibull_distribution<> u(2.0, 3.5);
+ VERIFY( u.a() == 2.0 );
+ VERIFY( u.b() == 3.5 );
+ VERIFY( u.min() == 0.0 );
+ typedef std::weibull_distribution<>::result_type result_type;
+ VERIFY( u.max() == std::numeric_limits<result_type>::max() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/operators/serialize.cc
new file mode 100644
index 00000000000..bf548d3feb6
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/operators/serialize.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.4 Class template weibull_distribution [rand.dist.pois.weibull]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringstream str;
+ std::weibull_distribution<double> u(2.0, 3.5), v;
+ std::minstd_rand0 rng;
+
+ u(rng); // advance
+ str << u;
+
+ VERIFY( !(u == v) );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/requirements/typedefs.cc
new file mode 100644
index 00000000000..acdea1d22b1
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/requirements/typedefs.cc
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+//
+// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 26.4.8.3.4 Class template weibull_distribution [rand.dist.pois.weibull]
+// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist]
+
+#include <random>
+
+void
+test01()
+{
+ typedef std::weibull_distribution<double> test_type;
+
+ typedef test_type::result_type result_type;
+}