ofRandom not working, or is it me?

Hoi Hoi!

A ridiculously simple question:
I’m creating a particle system and I am initalizing the initial position of the particles using ofRandom().
The second ofRandom (the one which assigns a value to loc.y) does not work properly, I get zeroes all the time:

#define WWIDTH 400  
#define WHEIGHT 400  
#define ARRAYNR 5  
void testApp::reset() {  
	//some random bodies  
	for(int i=0; i<ARRAYNR; i++) {  
		ofxVec2f ac = (0.0, 0.0);  
		ofxVec2f ve = (0.0, 0.0);  
		ofxVec2f location = (ofRandom(0, WWIDTH), ofRandom(0, WHEIGHT));  
                printf("location = %f, %f\n", lo.x, lo.y);//just to check the results  
		t[i].setup(ac, ve, lo, ofRandom(8, 16));  

This is what I get in the console:
location = 381.044678, 0.000000
location = 328.735016, 0.000000
location = 58.111752, 0.000000
location = 91.009216, 0.000000
location = 219.076782, 0.000000

As a result, all the particles are drawn at the top of the window.
What’s the problem?? Thanks in advance!


Beatriz ;D

1 your username is awesome (sublime?)

2 you can’t set the location like that, i’m surprised it even compiles, you should try this instead:

ofxVec2f location(ofRandom(0, WWIDTH), ofRandom(0, WHEIGHT));


ofxVec2f location;
location.set(ofRandom(0, WWIDTH), ofRandom(0, WHEIGHT));

Hi Kyle,

Thanks, that was the problem!

About my username, well, I hadn’t thought it that way hehehe


Beatriz ;D