security - Generate cryptographically secure random numbers in php -


PHP's rand () function does not give a good random number. That's why I have started using mt_rand () , which has been asked to give better results. But how good are these results? Is there any way to improve them again?

My thoughts:

  function rand_best ($ min, $ max) {$ gener = array (); {$ Generated for $ i = 0; $ i <100; $ i ++) [=] mt_rand ($ min, $ max); } Shuffle ($ generated); $ Position = MT_REND (0, 99); Return $ generated [$ position]; }  

It should give you a "perfect" random number, should not it?

(PRNG) are very complex animals.

There are no real "perfect" random number generators - really the best that math functions can be pseudo-random - they are random enough for most intentions and purposes.

In fact, performing any additional actions by the number returned by a PRNG does not actually increase its randomness, and in reality, the number can be less random.

So, my best advice is to not mess with the prices returned from any PRNG. Use a PRGG that is sufficient for the desired use, and if it is not, then it can get a PRNG which can produce better results if necessary.

And obviously, it seems that the function, which is a very good PRNG, so it will probably be enough for the most comfortable use.

Edit

There was a question in which it could make less random because of taking action on a random number. For example, some RPGs can return more consistent, less random numbers in different parts of bits - the high end may be more random than the lower end.

Therefore, the end is removed, and the lower end is returned, the value can be less than the original value returned from PRNGs.

I do not find a good explanation at the moment, but I have a java documentation for the method based on it, which is designed to create a fairly random value in a specific category. In this method, the difference in the randomness of some parts of the value has been taken into account, so it can return a more random sensitivity such as a better random number than rand ()% category .


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -