I would like to control the output of the below random function. I want that it return a number between the min and the max parameters. but it didn't. can you tell what should I change to do that. in the web, I found that 10000 should be the maximun that can be generated
I use a f340 with the tcp-ip conf wiz.
int random(int min, int max){ int res = min + (int)(my_rand()/10000*(max-1)); return res; }
I understand what you said about probability of occuring. can you tell me the way to make it right?
Somewhat better in terms of distribution would be:
long tmp; tmp = my_rand(); tmp = tmp * (max - min); tmp = (tmp + (MAX_RAND / 2)) / MAX_RAND; tmp = tmp + min;
Of course, the price to pay is additional computational effort (multiplication and division take a while on a '51, especially with long integers).
Of course, the price to pay is additional computational effort (multiplication and division take a while on a '51, especially with long integers). he clearly does not care about that, he uses an int for TRUE/FALSE. He crossposted at the SILabs forum www.cygnal.org/.../002446.html
Erik