This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

rand function

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;
}

Parents
  • You have also forgotten (a second time) to read the information how to post source code, despite Andy specifically notifying you about it - and posting a link.

    Now, it is time for you to pick up the documentation for rand(). It normally returns integer values between 0 and RAND_MAX, so RAND_MAX should be a good constant to make use of.

    It is quite unlikely that your RAND_MAX is 10000. A more common value is 32767 or 65535 or any other 2^n-1 value.

Reply
  • You have also forgotten (a second time) to read the information how to post source code, despite Andy specifically notifying you about it - and posting a link.

    Now, it is time for you to pick up the documentation for rand(). It normally returns integer values between 0 and RAND_MAX, so RAND_MAX should be a good constant to make use of.

    It is quite unlikely that your RAND_MAX is 10000. A more common value is 32767 or 65535 or any other 2^n-1 value.

Children