Results in result2.txt repeats every ~100 string. Yes, same surnames and same rand(100000, 999999) results are cycling every 100 values
NetBeans 8.0.2
//Get surname
$famtxt = file('surname.txt');
$surname = $famtxt[ array_rand($famtxt) ];
unset($famtxt);
//Results
$result0=$surname.' '.rand(100000, 999999);
$resulttxt = fopen('result2.txt', 'a');
fwrite($resulttxt,$result0);
Never use rand
, there are better functions out there, namely
http://php.net/manual/en/function.random-int.php
Generates cryptographic random integers that are suitable for use where unbiased results are critical (e.g. shuffling a Poker deck).
or
http://php.net/manual/en/function.mt-rand.php
Many random number generators of older libcs have dubious or unknown characteristics and are slow. By default, PHP uses the libc random number generator with the rand() function. The mt_rand() function is a drop-in replacement for this. It uses a random number generator with known characteristics using the » Mersenne Twister, which will produce random numbers four times faster than what the average libc rand() provides.
(Emphasis added by me) The speed is a nice bonus, but the fact that its using MT
will give you "randomer" numbers than just rand
.
AWW! It was just a terrible NetBeans IDE 8.0.2 trouble with pseudorandom generator. Script works fine on a server