Generate cryptographically secure random numbers in php

后端 未结 16 1658
孤街浪徒
孤街浪徒 2020-11-29 07:39

PHP\'s rand() function doesn\'t give good random numbers. So I started to use mt_rand() which is said to give better results. But how good are thes

16条回答
  •  既然无缘
    2020-11-29 08:25

    I wrote a cronjob that gets 1000 numbers from random.org periodically (say, once an hour) and added them into a PHP array. Whenever I want random numbers in my script, I use mt_rand(0,1000) to call a number from that. A few extra microseconds of overhead, but I get truly random numbers based on natural atmospheric noise.

提交回复
热议问题