On Tue, 20 May 2008 15:44:20 -0700, <qg**********@mailinator.comwrote:
Well, I am getting ready to live work so I slapped something together
hopping it will do what you need and it not buggy :)
I only found one bug: no need to subtract 1 from "seconds", as
Random.NextDouble() returns [0, 1), not [0, 1] (that is, it will never
actually return 1.0). By subtracting one, you guarantee that second 3599
will never be populated, which isn't correct.
To the OP: see what I mean? This is an entirely different solution, with
very different results, and yet it meets at least as much of the criteria
stated as any other solution could (including the one I posted).
That said, I'd clean it up a bit. Without changing too much of the
original style:
//...assume initialization, etc.
while (accumulatedHits++ < hits)
{
randomHits[rd.Next(seconds)]++;
}
Of course, as "hits" gets larger (and the proposed count was 20000, not
2000), the relative uniformity of distribution of hits over the seconds
becomes very even. Even with as few as a few hundred, it's reasonably
even (albeit sparse), and at 20000, it's definitely starting to get
difficult to tell the difference between incrementing per-second counters
randomly, and just initializing them all to "hits / seconds".
But of course, this solution _does_ in fact meet at least one version of
what the OP asked for. That's the problem with ambiguous problem
descriptions. :)
Pete