How is it done? Is this correct? If not why?
int nr;
nr = rand() % 200 - 100;
How is it done? Is this correct? If not why?
int nr;
nr = rand() % 200 - 100;
That depends on exactly what you mean by "randomize number from -100 to 100". To me, that sounds like you want a shuffle routine. However, if you just want a random number in that range (inclusive) then you've almost got it:
Code:nr = rand() % 201 - 100;
Thx!
Please read the last post here about the ideal way to do this.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
Very good point, iMalc. I had noticed a while ago that there was a bias but hadn't thought of a way to fix it.