answersLogoWhite

0

#include<iostream>

#include<iomanip>

#include<map>

#include<random>

#include<time.h>

std::default_random_engine generator;

std::uniform_int_distribution<unsigned> distribution (1, 10);

typedef std::map<unsigned, unsigned> freq_map;

int main()

{

std::cout << "Program to generate 1,000,000 random numbers in the range 1 to 10\n";

std::cout << "and to print the frequency table for all numbers generated.\n\n";

generator.seed ((unsigned) time (NULL));

freq_map fmap;

freq_map::iterator iter;

for (unsigned count=0; count<1000000; ++count)

{

unsigned number = distribution (generator);

iter = fmap.find (number);

if (iter == fmap.end())

{

fmap.insert (freq_map::value_type (number, 1));

}

else

{

++(iter->second);

}

}

for (iter = fmap.begin(); iter != fmap.end(); ++iter)

{

std::cout << "The number" << std::setw(3) << iter->first;

std::cout << " occurred" << std::setw(7) << iter->second << " times\n";

}

std::cout << std::endl;

}

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

What is The sum of the squares of two consecutive positive even integers is 340 Find the integers?

The sum of the squares of two consecutive positive even integers is 340. Find the integers.


Find the two consecutive positive integers is 132 find the integers?

The numbers are 65 and 67.


How can you find the total value of a combination of negative and positive integers?

Combine them together, using the rules of priority (PEMDAS or BIDMAS).


How do you find the sum of all the positive integers of a number?

By adding whatever you mean with "integers of a number".


The sum of the squares of two consecutive positive even integers is 340 Find the integers?

12 and 14.


Where can you find the number 15?

In a list of positive integers less than 20.


How do you subtract negative integers and how to find the distance between 2 integers without using a number line?

To subtract negative integers, you can convert the subtraction into addition by changing the sign of the negative integer. For example, subtracting -3 is the same as adding 3: ( a - (-b) = a + b ). To find the distance between two integers, simply calculate the absolute difference between them using the formula ( |a - b| ), which gives you a positive number representing the distance irrespective of their order.


The sum of the square of two consecutive positive even integer is 340 Find the integers?

The integers are 12 and 14 (144+196=340)


What is a good place to find a least common multiple?

In the set of positive integers.


How do you do integers greatest to least?

Positive integers are greater than negative integers. For positive integers: * The integer with more digits is larger. * If two integers have the same length, compare the first digit. If the first digit is the same, compare the second digit, then the third, etc., until you find a difference. In each case, the integer with the larger digit (at the first position where you find a difference) is the larger one.


Find consecutive negative integers whose sum is 110?

There is no solution.Consecutive negative integers will always add up to a negative number. 110 is positive.


The sum of two positive Integer is 108 one integer is three times as great as the other. find the integes?

The sum of two positive integers is positive