How would I do this?
This is my attempt of doing so:
srand (time(NULL));
seed = ((double)rand()) / ((double)RAND_MAX) * 10 + 0.5;
Also what is the way of creating a random integer between 0 and some int x. [0,x]
How would I do this?
This is my attempt of doing so:
srand (time(NULL));
seed = ((double)rand()) / ((double)RAND_MAX) * 10 + 0.5;
Also what is the way of creating a random integer between 0 and some int x. [0,x]
The C++11 way:
If you only want integers, use this distribution instead:
C++11 is really powerful and well-designed in this respect. The generators are separate from the choice of distribution, ranges are taken into account, thread safe, performance is good, and people spent a lot of time to make sure it's all correct. That last part is harder to get right than you think.
To show up to 2 decimal places:
If the
x
you need is smaller thanRAND_MAX
, then useto generate an integer in
[0, x]
.