yns
April 24, 2013, 12:34am
#1
I’m trying to control the amount of randomness with a global variable but I get weird results.
Basically I’m declaring a float at the top of my code and using it in testApp::update to be multiplied with ofRandom:
float rectRand = 100;
cout << ofRandom(1) * 100 << endl;
I get extremely small numbers:
1.26117e-44
8.40779e-45
1.68156e-44
5.60519e-45
2.8026e-45
1.4013e-45
4.2039e-45
5.60519e-45
2.8026e-45
1.54143e-44
1.12104e-44
1.4013e-44
7.00649e-45
8.40779e-45
1.54143e-44
5.60519e-45
0
1.12104e-44
2.8026e-45
And whenever I’m using an int instead of float (int rectRand = 100) I seem to get only values between 0 and 13:
4.43989
2.45417
5.47276
11.19
12.3605
6.39323
3.79754
2.10299
6.60152
4.9348
2.72991
5.49871
3.03373
What am I missing here?
yns
April 29, 2013, 10:26am
#2
Apparently I had to make the variable a double.
Any suggestions why?
hm, this is really weird, but I can’t reproduce it.
This in emptyExample update() function:
float myFloat = 100.0;
int myInt = 100;
double myDouble = 100.0;
ofLog(OF_LOG_NOTICE, "Int: %g, Float: %g, double: %g", ofRandom(1) * myInt, ofRandom(1) * myFloat, ofRandom(1) * myDouble);
gives, as expected:
[notice] Int: 42.8355, Float: 16.327, double: 12.994
[notice] Int: 28.4969, Float: 4.48999, double: 47.831
[notice] Int: 54.7669, Float: 69.9344, double: 16.6802
[notice] Int: 42.5372, Float: 97.0982, double: 19.3167
[notice] Int: 35.294, Float: 92.8939, double: 35.7759
[notice] Int: 96.4609, Float: 96.7863, double: 28.0223
[notice] Int: 35.7959, Float: 38.8857, double: 65.8181
[notice] Int: 55.5719, Float: 66.0126, double: 16.9108
[notice] Int: 49.6267, Float: 40.8757, double: 9.09463
[notice] Int: 27.476, Float: 58.2255, double: 5.75573
[notice] Int: 43.803, Float: 71.2196, double: 83.8503
[notice] Int: 48.293, Float: 19.0505, double: 26.6858
yns
April 29, 2013, 2:11pm
#4
Thanks for your reply!
You’re right. I was trying to set an index an with a bigger index than it’s size (array had size 2 and I was doing array[2]). That messed up everything. I wonder why though. I would have expected xcode not to compile in a case like this anyway.