开发者

FreqTable with random values(#C)

I would like to make a frequency table with random numbers. So i have created a array that generates 11 random values between 0 and 9999.

        public void FillArrayRandom(int[] T)
    {
        Random Rndint = new Random();

        for (int i=0; i < T.Length; i++)
        {
            T[i] = Rndint.Next(0, 9999);
        }
    }/*FillArrayRandom*/

The result i want is something alike this:(bar height up to 21) So this will be a constant.

                 *
        *        *
  *     *        *          (the highest value will have the largest row/bar)
  *     *    *   *
  0     1    2   3  .....(index value's)
931   6669  10 8899 .... (up to 11 random values)

My question is how do i exactly caculate the frequency between those 11 random values? The bars should have a relative relation with each other depe开发者_运维百科nding on there frequency. I would only like to use 1 single array in my program (for the generated values).

F = (F * 21?) / ...? Really no clue how to obtain the proper results.

If a frequency is >=21 write * If a frequency is >=20 write * If a frequency is >=19 write * , and so on until i reach 1. (and the full table is displayed

Basicly i would like to print the table line per line with consolewrite(line).

etc...

Regards.


To calculate frequency you could use a Dictionary defined something like:

freqDict Dictionary<int, int> = new Dictionary<int, int>();

Where the first integer (K) is the key that corresponds to your random value or its index in the values array, either way it has to be unique and able to reference to a particular value. The second integer is the value (V) that is your count of each key.

Next, walk your array of randomly generated values and if it's not represented in the dictionary add it with the new key and set the value to 1. If the dictionary already contains the key you simply increment the value by 1. Do this for each value in your rand array and you will have a dictionary with a frequency distribution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜