In pratice, the approach of separate RNGs with different seeds for threads/processes is widely used (even though theoretically those RNGs might have overlaping sequences, which is undesirable). For more discussions on this approach, please refer to The Rust Rand Book - Parallel RNGs and Seed Many RNGs in Rust . The …
Collections and Iterators in C++
Collections
-
Prefer
std::deque
tostd::vector
when the size of the collection is unknow. -
Suppose set
A
andB
are two set with the same type and setC
is another set with the same value type but a different comparison function, then it is still valid to insert …
Boolean Values in C++
-
Boolean expressions are evaluated from left to right (the same in Java), so it is totally OK to write code like
if(a < x.size() && x[a]){ ... }
where
x
is a vector. -
There is no
&&=
and||=
operators in C++, instead you can use&=
and|=
. Though&=
and|=
are not specially for …
Probability to Lose All Money
A few days ago I found someone asking an interview questions on mitbbs. The question is as follows. A gambler plays a fair game and bet 1 dollar each time. If he lose all his money, the game stops. Suppose he has 10 dollars and is only allowed to play …
Working with Class in C++
Illustrative examples for the following discussions can be found here.
-
It is suggested that you also provide a default constructor if you ever provide a user-defined constructor when writing a C++ class.
-
If you want to allow deleting a derived class from a pointer of the base class, you have …
Input and Output in C++
Check the io
directory on the page https://bitbucket.org/dclong/cpp-learn/src
for some illustrative examples for the following discussions.
-
You can format output of numbers using functions
std::setpresicion
andstd::setw
in theheader. -
When you read data from a file into an array or write data …