Vous êtes sur la page 1sur 2

#include "std_lib_facilities_3.h" #include "randint.h" #include <chrono> /* This program modifies Homework 5 Problem 2 with a 'better_random_int()' funct ion.

Counts the last decimal digit of random digits. This file is included in Homework 6 in order to create FLTK rectangles of a certain length. */ using namespace std::chrono; int randint() { static long x = time_point_cast<microseconds>( system_clock::now()).time_since_epoch().count(); x = (1103515245 * x + 12345) & 0x7fffffff; return x; } int better_random_digit() { int y; int last_digit2; while (y < 1000) { y = randint() >> 21; last_digit2 = y % 10; } return last_digit2; } void count_digit(int n, vector<int>& count) { switch(n) { case 0 : ++count[0]; break; case 1 : ++count[1]; break; case 2 : ++count[2]; break; case 3 : ++count[3]; break; case 4 : ++count[4]; break; case 5 : ++count[5]; break; case 6 : ++count[6]; break;

case 7 : ++count[7]; break; case 8 : ++count[8]; break; case 9 : ++count[9]; break; default: break; } } int better_random_digit();

Vous aimerez peut-être aussi