I need to randomly generate numbers (using random()) from -1 to 1 that are doubles. For example the output would be something like:
1, -0.3324, 0.7821, 0.9823, -0.111
etc... this is what I was trying to do walk_Length = (double)rand()%2 - 1;
I need to randomly generate numbers (using random()) from -1 to 1 that are doubles. For example the output would be something like:
1, -0.3324, 0.7821, 0.9823, -0.111
etc... this is what I was trying to do walk_Length = (double)rand()%2 - 1;
You might get away with something like
double walk_Length = static_cast<double>(rand()) / RAND_MAX * 2 - 1;