fValisHP is the final output of the program, and as such is a globalCode:for(;iINum>0;iINum--) { cout<<fValisHP<<endl; fValisHP+=rand(2.0,4.0); cout<<fValisHP<<endl; } float rand(float arg1,float arg2) { float fRandom; float fRange=(arg2-arg1); fRandom=arg1+float(fRange*rand()/(RAND_MAX)); float ind; for(ind=2.0;ind<=4.0;ind+=0.1) { if((fRandom>=(ind-0.05))&&(fRandom<(ind+0.05))) { fRandom=ind; break; } } return fRandom; }
variable. The 'couts' are there to check that value before and after
the random call. Even though I use the srand function at the beginning
of the program (take my word for it), the first value output by rand is
always the same. If I enter an iINum greater than 1 (but not greater
than 4) the numbers AFTER the first are 'random', but the first one
still is not. What can I do to fix this?
btw, daved, I thought I tried the return on the input reject function,
but I did what you said and it worked this time. Thanks.



LinkBack URL
About LinkBacks


