How to generate a random number?

How to generate a random integer with specific range(for example, from 1 to 1000)?

Also, how to convert a floating point number into a integer?

You can use srand() to generate a random number. Then use the modulus operator to get a number between 1 and 1000. I dont remember the exact syntax..but it would something like

your_random_number = srand() % 1001

Good Luck.. :slight_smile:

From the linux rand(3) man page:

In other words, under Linux your algorithm is probably fine, on other architectures it may not be very random. For portability, use the noted syntax or check the man page for your particular rand implementation.