PHP function mt_rand ()

Are PHP random numbers predictable? if so, how difficult would it be to predict random numbers that range from 1 to 32? and is there any way to make this unpredictable?

<?php function rand_best($min, $max) { $generated = array(); for ($i = 0; $i < 100; $i++) { $generated[] = mt_rand($min, $max); } shuffle($generated); $position = mt_rand(0, 99); return $generated[$position]; } ?> 
+4
source share
2 answers

A discussion of how random random functions in programming is ancient.

Take a look at this: http://en.wikipedia.org/wiki/Random_number_generation

Anyway. Random functions are so good today that they (what I would call) were as random as possible. There is no way to predict the result between 1.32 (or any other number for this). The fact is that the numbers are not really random, because the computer cannot perform such an operation.

I would say that the rand functions are more than good enough if you are not writing something for the Pentagon

+6
source

Assuming a Linux system, you can generate your pseudo-random number generator / dev / urandom (or read this) or perhaps /dev/random (be careful, it might block).

+2
source

Source: https://habr.com/ru/post/1389444/


All Articles