I am having problem with mt_srand function.
....
echo mt_srand((double)microtime()*10000);
...return nothing
I believe it does not work. I am running php 4.2 and it should work just fine. The other random functions including mt_rand(,) work as described in books. I do have php instaled on windows 2000. Any ideas why it is not working?
Help with mt_srand
because mt_srand() is used to seed the Mersenne Twister pseudorandom number generator.
it doesnt generate pseudorandom numbers.
Strange the function is being used a lot on php.net site.
What I was going to do is to use is with mt_rand().
I was going to do something like this
$random = mt_srand((double)microtime()*10000);
mt_rand(0, $random);
Can you suggest alternative?
Yes.
I suggest:
mt_srand((double)microtime()*10000);
$random = mt_rand(0, $random);
Sorry, but I do not see any difference. Also $random in your suggestion in line 2 is not defined
Sorry, but I do not see any difference.
Then I suggest you read the PHP manual on the difference between [man]mt_rand[/man] and [man]mt_srand[/man].
Basically, the former generates the pseudorandom numbers, the latter seeds the generator to provide some element of randomness.
Also $random in your suggestion in line 2 is not defined
$random in your original code on line 1 is not defined either.
There is no problem since this variable is initialised on those lines.
Perhaps I did not explained correctly. I do know the difference between mt_srand and mt_rand.
What I meant is that your code looked exactly as my code.
I do know the difference between mt_srand and mt_rand.
then explain the difference.
to me it is clear that you misunderstand what mt_srand() does.
you only need to read the PHP manual to see that
$random = mt_srand((double)microtime()*10000);
is as good as
$random = NULL;
EDIT:
though $random = NULL isnt quite the same, I should say.