If you use MCRYPT_RAND, make sure to call srand() before to initialize the random number generator.
mcrypt_create_iv() takes two arguments, size determines the size of the IV, source specifies the source of the IV.