Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all. I have a question. In c++ 11 have a standard function discrete_distribution for Discretely Distributed Random Numbers

Example:

C++
#include <iostream>
#include <random>

int main()
{
  const int nrolls = 10000; // number of experiments
  const int nstars = 100;   // maximum number of stars to distribute

  std::default_random_engine generator;
  std::discrete_distribution<int> distribution {2,2,1,1,2,2,1,1,2,2};

  int p[10]={};

  for (int i=0; i<nrolls; ++i) {
    int number = distribution(generator);
    ++p[number];
  }

  std::cout << "a discrete_distribution:" << std::endl;
  for (int i=0; i<10; ++i)
    std::cout << i << ": " << std::string(p[i]*nstars/nrolls,'*') << std::endl;

  return 0;

}


Result:

a discrete_distribution:
0: ************
1: *************
2: *****
3: ******
4: ************
5: ************
6: ******
7: ******
8: ************
9: ************




In c# have standard function like discrete_distribution in c++ ??? Thanks all!
Posted
Updated 5-Oct-15 10:32am
v2

How write. do you have programm? talk me please!
 
Share this answer
 
Comments
Matt T Heffron 6-Oct-15 16:42pm    
Two points:
#1. To respond to Dave Kreskowiak use the "Have a Question or Comment?" button that is below his name in Solution 1. That way he will get an email telling him that you have a question, and he can reply. Posting it as a Solution does not notify him. (And it may appear to be abuse of the "Reputation Points" system here on Code Project.)
#2. He did say "You'd have to write..." which means you'll need to learn to implement this in C#.
There is no such class/method in the .NET Framework. You'd have to write your own implementation in C#.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900