dongzuo7166 2017-02-03 00:17
浏览 79
已采纳

通过拥有许多输出来预测PHP rand()

I was wondering if it possible to predict the next pseudo random number that will be generated out of PHP rand() function, by using the previous outputs of it.

An example would be that I have n outputs of rand(1,10) like 8, 5, 10, 3, 3, 2 ... 9, 8 ... and so on.

So the question is, is there any way that I can use these already generated numbers to predict the next one?

EDIT

Since the question was marked as too broad, I will try to be more specific. Can I predict the next RGN or recover the seed, on PHP running on Linux, when using the rand() function, by only observing some outputs given from it.

A concrete example is the following output:

21962

10038

10425

17032

Generated by the following code:

<?php
echo rand(1, 68703);
  • 写回答

1条回答 默认 最新

  • douxin8749 2017-02-03 03:27
    关注

    Not sure what is under the hood, but it is likely covered by one of these links:

    If it is not covered, then provide me the source code and I will break it.

    EDIT: As requested in comments below, I update my answer.

    One trivial way to break it is brute force search of the srand seed. Normally this is a 32-bit int (which will take a few minutes to brute force), but on some platforms it may be 64-bit (takes too long to break via brute force). So you just loop through each candidate seed, do srand( candidate seed) and then generate your rand(1, 68703) to see if it matches the outputs. If so, you presumably have the right seed and can generate future outputs. Otherwise continue loop.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂