This will not play well with other random code ...
#include <ctime> #include <cstdlib> struct RandomInt { RandomInt() { static bool initialized = (srand(std::time(0)), true); } operator int() { return std::rand(); } }; #include <iostream> std::ostream& operator<<( std::ostream& stream, RandomInt x ) { return stream << static_cast<int>(x); } int main() { RandomInt randomInt; std::cout << randomInt << "\n"; std::cout << randomInt << "\n"; std::cout << randomInt << "\n"; }
This is a pretty bad idea.
source share