43 inline double rand(
double a = 0,
double b = 1)
45 std::uniform_real_distribution<> ud(a, b);
47 #ifdef _NO_THREAD_LOCAL_
51 #endif // _NO_THREAD_LOCAL_
63 bigint b = std::numeric_limits<bigint>::max())
65 std::uniform_int_distribution<bigint> uid(a, b);
67 #ifdef _NO_THREAD_LOCAL_
71 #endif // _NO_THREAD_LOCAL_
83 ubigint b = std::numeric_limits<ubigint>::max())
85 std::uniform_int_distribution<ubigint> uid(a, b);
87 #ifdef _NO_THREAD_LOCAL_
91 #endif // _NO_THREAD_LOCAL_
103 idx b = std::numeric_limits<idx>::max())
105 std::uniform_int_distribution<idx> uid(a, b);
107 #ifdef _NO_THREAD_LOCAL_
111 #endif // _NO_THREAD_LOCAL_
125 template<
typename Derived>
162 if ( rows == 0 || cols == 0 )
166 return dmat::Zero(rows, cols).unaryExpr(
199 if ( rows == 0 || cols == 0 )
203 return rand<dmat>(rows, cols, a, b).cast<cplx>() +
204 1_i * rand<dmat>(rows, cols, a, b).cast<cplx>();
218 template<
typename Derived>
253 double mean,
double sigma)
257 if ( rows == 0 || cols == 0 )
261 std::normal_distribution<> nd(mean, sigma);
263 return dmat::Zero(rows, cols).unaryExpr(
266 #ifdef _NO_THREAD_LOCAL_
270 #endif // _NO_THREAD_LOCAL_
297 double mean,
double sigma)
301 if ( rows == 0 || cols == 0 )
305 return randn<dmat>(rows, cols, mean,
sigma).cast<cplx>() +
306 1_i * randn<dmat>(rows, cols, mean,
sigma).cast<cplx>();
319 std::normal_distribution<> nd(mean,
sigma);
321 #ifdef _NO_THREAD_LOCAL_
325 #endif // _NO_THREAD_LOCAL_
344 cmat X = 1 / std::sqrt(2.) * randn<cmat>(D, D);
345 Eigen::HouseholderQR<cmat> qr(X);
347 cmat Q = qr.householderQ();
351 Eigen::VectorXcd phases = (rand<dmat>(D, 1)).cast<
cplx>();
352 for (
idx i = 0; i < static_cast<idx>(phases.rows()); ++i )
353 phases(i) = std::exp(2 *
pi * 1_i * phases(i));
355 Q = Q * phases.asDiagonal();
371 if ( Din == 0 || Dout == 0 || Din > Dout )
375 return randU(Dout).block(0, 0, Dout, Din);
398 std::vector<cmat> result(N);
399 for (
idx i = 0; i < N; ++i )
400 result[i] = cmat::Zero(D, D);
406 #pragma omp parallel for collapse(3)
408 for (
idx k = 0; k < N; ++k )
409 for (
idx a = 0; a < D; ++a )
410 for (
idx b = 0; b < D; ++b )
411 result[k](a, b) = U(a * N + k, b * N);
430 cmat H = 2 * rand<cmat>(D, D) - (1. + 1_i) * cmat::Ones(D, D);
456 ket kt = randn<cmat>(D, 1);
458 return kt /
norm(kt);
476 result = result *
adjoint(result);
478 return result /
trace(result);
498 std::vector<idx> result(n);
501 std::iota(std::begin(result), std::end(result), 0);
503 #ifdef _NO_THREAD_LOCAL_
504 std::shuffle(std::begin(result), std::end(result),
507 std::shuffle(std::begin(result), std::end(result),
510 #endif // _NO_THREAD_LOCAL_
idx randidx(idx a=std::numeric_limits< idx >::min(), idx b=std::numeric_limits< idx >::max())
Generates a random index (idx) uniformly distributed in the interval [a, b].
Definition: random.h:102
Eigen::MatrixXd dmat
Real (double precision) dynamic Eigen matrix.
Definition: types.h:71
unsigned long long int ubigint
Non-negative big integer.
Definition: types.h:46
std::vector< cmat > randkraus(idx N, idx D)
Generates a set of random Kraus operators.
Definition: random.h:388
ket randket(idx D)
Generates a random normalized ket (pure state vector)
Definition: random.h:441
Eigen::VectorXcd ket
Complex (double precision) dynamic Eigen column vector.
Definition: types.h:56
Quantum++ main namespace.
Definition: codes.h:30
double norm(const Eigen::MatrixBase< Derived > &A)
Frobenius norm.
Definition: functions.h:252
double sigma(const std::vector< double > &prob, const Container &X, typename std::enable_if< is_iterable< Container >::value >::type *=nullptr)
Standard deviation.
Definition: statistics.h:207
std::vector< idx > randperm(idx n)
Generates a random uniformly distributed permutation.
Definition: random.h:490
dyn_mat< typename Derived::Scalar > adjoint(const Eigen::MatrixBase< Derived > &A)
Adjoint.
Definition: functions.h:84
static RandomDevices & get_thread_local_instance() noexcept(std::is_nothrow_constructible< RandomDevices >::value)
Definition: singleton.h:102
std::complex< double > cplx
Complex number in double precision.
Definition: types.h:51
Generates custom exceptions, used when validating function parameters.
Definition: exception.h:39
Derived randn(idx rows, idx cols, double mean=0, double sigma=1)
Generates a random matrix with entries normally distributed in N(mean, sigma)
Definition: random.h:219
cmat randU(idx D)
Generates a random unitary matrix.
Definition: random.h:334
Derived::Scalar trace(const Eigen::MatrixBase< Derived > &A)
Trace.
Definition: functions.h:127
constexpr double pi
Definition: constants.h:79
cmat randH(idx D)
Generates a random Hermitian matrix.
Definition: random.h:422
double rand(double a=0, double b=1)
Generates a random real number uniformly distributed in the interval [a, b)
Definition: random.h:43
static RandomDevices & get_instance() noexcept(std::is_nothrow_constructible< RandomDevices >::value)
Definition: singleton.h:90
long long int bigint
Big integer.
Definition: types.h:41
Eigen::MatrixXcd cmat
Complex (double precision) dynamic Eigen matrix.
Definition: types.h:66
cmat randrho(idx D)
Generates a random density matrix.
Definition: random.h:467
std::size_t idx
Non-negative integer index.
Definition: types.h:36
cmat randV(idx Din, idx Dout)
Generates a random isometry matrix.
Definition: random.h:367