Kai-Uwe Bux
10/10/2008 10:59:00 PM
Joe, G.I. wrote:
> Hi all,
>
> I'm trying to generate about 50 numbers as milliseconds between 0 and 4
> seconds and it's driving me crazy.
>
> Can anyone help out on how to do this? Any help much appreciated.
a) What is the desired type:
- double
- long double
- float
- (unsigned int) with 4 being 4000ms
b) Once you settled on the type, write a function that generates one random
number in the desired range. Some care is needed to get this uniform
(which, I think, is an implicit requirement of yours).
c) Call that function 50 times.
d) If you do not need 50 durations, but 50 points on the time arrow, you
might want to sort the 50 results so that they line up nicely. Note that
you might have doubles.
e) If you need 50 distinct values between 0 and 4, you could use a std::set
and insert every random value as it is generated. Iterate until the size is
50.
Best
Kai-Uwe Bux