Generate random double number between 0.0 and 1.0, then check the frequence in CSharp
Description
The following code shows how to generate random double number between 0.0 and 1.0, then check the frequence.
Example
using System;// w w w .j a v a 2s . c o m
public class Example
{
public static void Main()
{
int[] frequency = new int[10];
double number;
Random rnd = new Random();
for (int ctr = 0; ctr <= 99; ctr++) {
number = rnd.NextDouble();
frequency[(int) Math.Floor(number*10)] ++;
}
for (int ctr = frequency.GetLowerBound(0); ctr <= frequency.GetUpperBound(0); ctr++)
Console.WriteLine("0.{0}0-0.{0}9 {1}", ctr, frequency[ctr]);
}
}
The code above generates the following result.