How to use Rand() function correctly?