I have a simple piece of PHP code which requires a random number to be created. However, even though the input is always positive, it sometimes returns a negative output.
Rand takes as arguments, and returns, integers. Integers (in PHP) usually have a maximum range of 2**32.
Your double arguments are larger than this, causing an integer overflow when they are converted to integers.