C++ examples for Data Type:Random
Using Function srand to Randomize the die-rolling program
#include <cstdlib> #include <iomanip> #include <iostream> int main(int argc, const char *argv[]) { unsigned seed; std::cout << "Enter seed: "; std::cin >> seed;//from w w w. j a va2 s. c om srand(seed); for (int counter = 0; counter <= 10; ++counter) { std::cout << std::setw(10) << (1 + rand() % 6); if (counter % 5 == 0) std::cout << std::endl; } return 0; }