如何使用可逆种子使所有可能的列表组合?
我想拥有一个由100个项目制成的列表,每个项目都是0-31的值。然后,我希望能够获取以下列表之一,并知道随机生成该确切列表的必要种子/输入。
I want to have a list made out of 100 items, each item being a value from 0-31 inclusive. I then want to be able to take one of these lists, and know what seed/input is necessary to randomly generate that exact list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用一些适当的线性一致生成器:
您可以使用Pierre L'Ecuyer的这篇研究论文:
表rer” > LCGS IS 2 30 ,接近10亿。参见论文的表4。只需选择其中一个LCG,例如:
u n + 1 =((((116646453) * un ) + 5437)mod 2 30
您的物品正好宽5位。如果您决定将项目6乘6分组,则每个 group 恰好宽30位,因此可以被视为此Modulo 2 30 lcg的一个状态。
从最初的6个项目组中,LCG的一个步骤将生成下一个组,即接下来的6个项目。论文告诉您,意甲总体上看起来是合理的随机。
因此,您可以将前6个项目视为“种子”,因为您可以从最左边的6个项目中重建整个列表。
即使假设为了混淆,您在种子之后启动了列表的可见部分,您仍然只有大约十亿个可能的种子可以担心。任何体面的计算机都可以通过少数几秒钟的时间在几秒钟内通过蛮力找到剩下的种子,并通过为每种可能的种子模拟LCG并与实际列表进行比较。
示例Python代码:
一个人可以从创建一个类别的类中开始,该类给定种子,提供了一个无限的意甲,在0到31之间的项目:
测试代码:
我们可以创建20个项目的序列并打印它:
程序输出:输出:
Using some suitable Linear Congruential Generator:
You could use this research paper by Pierre L'Ecuyer:
Tables_of_linear_congruential_generators_of_different_sizes_and_good_lattice_structure
The lowest power of 2 modulus for which the paper gives examples of (decently pseudo-random) LCGs is 230, which is close to 1 billion. See table 4 of the paper. Just pick one of those LCGs, say:
un+1 = ((116646453 * un) + 5437) mod 230
Each of your items is exactly 5 bits wide. If you decide to group your items 6 by 6, each group is exactly 30 bits wide, so can be considered as one state of this modulo 230 LCG.
From a initial group of 6 items, one step of the LCG will generate the next group, that is the next 6 items. And the paper tells you that the serie will look reasonably random overall.
Hence, you can regard the first 6 items as your “seed”, as you can reconstruct the whole list from its leftmost 6 items.
Even assuming that for the sake of obfuscation you started the visible part of the list after the seed, you would still have only about one billion possible seeds to worry about. Any decent computer would be able to find the left-hidden seed by brute force within a handful of seconds, by simulating the LCG for every possible seed and comparing with the actual list.
Sample Python code:
One can start by creating a class that, given a seed, supplies an unlimited serie of items between 0 and 31:
Test code:
We can create a sequence of 20 items and print it:
Program output: