问题标签 [prng]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
236 浏览

c++ - 在 Crypto++ 中将 autoseed PNRG 的输出放入一个字符串中

我正在使用 Cryptopp 生成一个随机字符串。这是代码:

我已经在代码中添加了一个新的 var: string str = ""。然后在每个结果的 for append 中,字符串的一部分。但是我的输出很脏!我只看到奇怪的 ASCII 字符。我怎样才能很好地设置字符串?

谢谢你。

0 投票
0 回答
346 浏览

java - 我怎样才能让 Fortuna 生成器(来自 gnu 类路径的那个)正常工作?

出于某种原因,无论我尝试什么代码,这段代码总是输出一个

错误。我在消息底部包含了我的测试代码。此外,我一直无法找到此生成器的文档。而且我没有使用 gnu 类路径,我只是导入了 Fortuna.java 想要的类。

0 投票
2 回答
2085 浏览

java - 为什么 Java 中的 SecureRandom 称为 CS PRNG 而不是 TRNG?

SecureRandom 在内部使用了其他算法,例如 in case of Linux,使用NativePRNGwhich 反过来又使用/dev/urandom. 但/dev/urandom实际上是使用中断事件等来生成类似于真随机数生成器 (TRNG) 的熵。那么为什么SecureRandomPseudoRandom数字生成器,虽然它依赖于它所使用的算法的实现呢?

谢谢

0 投票
3 回答
5661 浏览

algorithm - 随机数生成器算法

银行使用什么算法生成随机数,例如(信用卡/借记卡号码)?

假设我维护数据库中的所有数字,如果我尝试以下方法,

  1. 生成一个随机数。
  2. 验证号码是否已经分配。
  3. 如果是,请转到步骤 1。
  4. 如果没有,则在数据库中为新号码创建记录并输出结果。

当卡容量增加时,它会要求更多的数据库命中。

对此还有什么看法吗??请帮忙。

0 投票
1 回答
698 浏览

racket - 如何在球拍中使用合同出局

我在 Racket 中写了一个免费的乘以进位 PRNG。我想用它provide来限制对我库中某些功能的访问,并对它们强加合同。使用球拍文档(上面链接),我已将以下代码放在我的文件顶部为此:

但是当我在 DrRacket 中运行该文件时,出现以下错误:

该代码在没有插入上述代码的情况下在 DrRacket 中运行时不会引发错误,并且可以正常工作。

限制仅访问源文件之外的某些功能以及在 Racket 中执行合同的正确方法是什么?

0 投票
2 回答
262 浏览

random - Trying to write an invertible PRNG of 8 bits, not a cipher

I'm trying to build a PRNG of bytes where I can take a set of bytes (say, 10 or 15 bytes) and return a list of seeds that would yield that list of bytes. I'm not concerned about cryptography, but it must be roughly uniformly distributed, it must hit all possible 2^8 combinations and it must occasionally be able to repeat a number without getting stuck.

The problem is, most algorithms I've read about either use ciphers, which probably means it won't allow repeats, or they use modulus or non-circular shifts that induce loss and make reversing the function impractical at best. Also, if the algorithm used counting, it would be hard to work backwards as the byte list input would not know what the internal PRNG's counter was at the generation time.

I realize what I'm looking for is a have-your-cake-and-eat-it-too situation, but I wanted to make sure there wasn't another solution I was missing.

While searching I came across this post which has similar requirements. I was writing in C# but really, syntax is not important.

Every algorithm I've tried to write myself has been a cipher and thus failed to repeat and/or not uniform in distribution. I used inversion, circular shifting and seed masking.

0 投票
1 回答
992 浏览

ruby - Ruby 的 SecureRandom 和 n 的大小

我正在寻找 6 个随机十六进制字符,并且正在使用 Ruby 的SecureRandom

SecureRandom.hex(3)将返回从 3 个字节的随机数据中解压缩的 6 个十六进制字符。

问题是,是否会SecureRandom.hex(6)[0,6]返回 6 个更随机的十六进制字符,因为在解包之前有 6 个字节的随机数据?就此而言,会SecureRandom.hex(16)[0,6]更加随机吗?

对于我的应用程序,我只需要具有超过 1600 万个唯一值的 6 个字符,但我希望与已经选择的数字发生冲突的机会尽可能低。那么使用更大n的随机字节会改善随机值在空间上的分布还是没有必要?

0 投票
1 回答
540 浏览

c++ - 使用 g++ 编译 C++ 文件时出错

我正在使用来自 cygwin 的 g++,我正在尝试编译一个 .cpp 文件,但我遇到了一个错误,

这是代码:

这是我在尝试使用 cygwin 终端和 g++ 进行编译时遇到的错误

.cpp 文件和头文件 randomc.h 位于我的 xampp 位置。我认为这根本不重要,不是吗?有人可以告诉我如何让它编译和运行吗?谢谢。

0 投票
2 回答
950 浏览

java - 在java中播种一个安全的随机数

以相同值作为种子的两个java.security.SecureRandom实例最初会给出相同的随机数序列吗?

我问这个是因为我想要客户端和服务器中的随机数序列相同。如果他们都使用相同的种子值怎么办。序列是否相同,或者有什么方法可以使序列相同?

0 投票
1 回答
3290 浏览

postgresql - PostgreSQL 的 random() 函数的质量?

假设我正在创建一个表foo,其列bar应该是一个非常大的随机整数。

这是最好的方法吗?谁能谈谈 PostgreSQLrandom()功能的质量?这里的乘法是否掩盖了熵?

请注意,我确实有很好的硬件熵输入/dev/random.