TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A Family of Better Random Number Generators

163 pointsby marcobambiniover 4 years ago

19 comments

celrodover 4 years ago
Xoshiro over PCG arguments: <a href="http:&#x2F;&#x2F;pcg.di.unimi.it&#x2F;pcg.php" rel="nofollow">http:&#x2F;&#x2F;pcg.di.unimi.it&#x2F;pcg.php</a><p>Response by the author: <a href="https:&#x2F;&#x2F;www.pcg-random.org&#x2F;posts&#x2F;on-vignas-pcg-critique.html" rel="nofollow">https:&#x2F;&#x2F;www.pcg-random.org&#x2F;posts&#x2F;on-vignas-pcg-critique.html</a><p>Personally, I use a SIMD Xoshiro256+ when I want a solid and fast RNG (although I mostly use Julia&#x27;s default -- a MersenneTwister).
评论 #24785844 未加载
评论 #24786103 未加载
评论 #24785769 未加载
评论 #24785609 未加载
rdwover 4 years ago
I used PCG years ago for procedural content generation where random number generation was a bottleneck. It is very fast, so I was happy with it. Additionally the implementation I used[1] is comprehensible enough that I could modify it in various small ways.<p>One property I anecdotally observed about it is that it is a little sensitive to the values you choose for its seed. Too many zero bits or making two generators with nearly-identical seeds would create visible correlation in the outputs. It worked much better if all values were hashed before using them for seeding.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;tlauterbach&#x2F;unity-pcg-csharp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tlauterbach&#x2F;unity-pcg-csharp</a>
plopilopover 4 years ago
The website does not seem to have been updated but the prediction security of PCG has been fully broken recently (and does not rely on the &quot;Challenging&quot; part of the spectrum): <a href="https:&#x2F;&#x2F;hal.inria.fr&#x2F;hal-02700791&#x2F;" rel="nofollow">https:&#x2F;&#x2F;hal.inria.fr&#x2F;hal-02700791&#x2F;</a><p>Hence any cryptographic use of PCG is definitely prohibited
评论 #24788919 未加载
评论 #24791817 未加载
nestorDover 4 years ago
On random numbers, I found the ideas behind &quot;Parallel Random Numbers: As Easy as 1, 2, 3&quot; [0] (which is implemented in JAX) interesting. Their generator is a mapping between keys and random numbers which get rid of the sequential dependency in the generator making it very easy to run in parallel at a GPU scale.<p>[0]: <a href="http:&#x2F;&#x2F;www.thesalmons.org&#x2F;john&#x2F;random123&#x2F;papers&#x2F;random123sc11.pdf" rel="nofollow">http:&#x2F;&#x2F;www.thesalmons.org&#x2F;john&#x2F;random123&#x2F;papers&#x2F;random123sc1...</a>
评论 #24786790 未加载
评论 #24792146 未加载
rainworldover 4 years ago
<p><pre><code> Statistical Quality PCG Family Excellent ChaCha20 Good </code></pre> What a joke.
评论 #24787542 未加载
评论 #24792960 未加载
评论 #24792793 未加载
andreareinaover 4 years ago
What applications require unpredictability where you wouldn&#x27;t go full csprng?
评论 #24786843 未加载
评论 #24785565 未加载
评论 #24790183 未加载
评论 #24785479 未加载
评论 #24785498 未加载
评论 #24791405 未加载
评论 #24785471 未加载
EE84M3iover 4 years ago
They describe rc4 as secure, which it hasn&#x27;t been considered for years, so I&#x27;m not sure how seriously to take this site
评论 #24785520 未加载
评论 #24785545 未加载
评论 #24785455 未加载
kevincoxover 4 years ago
I&#x27;ve used Pcg32 via <a href="https:&#x2F;&#x2F;docs.rs&#x2F;rand_pcg" rel="nofollow">https:&#x2F;&#x2F;docs.rs&#x2F;rand_pcg</a> and been quite happy. That being said I don&#x27;t rely on excellent quality and haven&#x27;t tested it. One of the main reasons I use it is that the implementation works perfectly in WebAssembly.<p>I use it to deal tiles in my version of online Azul: <a href="https:&#x2F;&#x2F;tiles.kevincox.ca" rel="nofollow">https:&#x2F;&#x2F;tiles.kevincox.ca</a><p>I also used it to simulate the Red7 game for strategy testing: <a href="https:&#x2F;&#x2F;gitlab.com&#x2F;kevincox&#x2F;red7-sim" rel="nofollow">https:&#x2F;&#x2F;gitlab.com&#x2F;kevincox&#x2F;red7-sim</a>
fsiefkenover 4 years ago
Is there a fork of Fortune that uses the PCG, Xoshiro or wyhash algorithm?<p>I am not fluent in C or Rust and time constrained, otherwise I would have taken a shot at it<p><a href="https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;shlomif&#x2F;fortune-mod&#x2F;master&#x2F;fortune-mod&#x2F;fortune&#x2F;fortune.c" rel="nofollow">https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;shlomif&#x2F;fortune-mod&#x2F;master...</a> <a href="https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;wapm-packages&#x2F;fortune&#x2F;master&#x2F;src&#x2F;main.rs" rel="nofollow">https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;wapm-packages&#x2F;fortune&#x2F;mast...</a><p>Or better, with an entropy source like rdrand or rdseed?
评论 #24794361 未加载
m4r35n357over 4 years ago
TinyCC example in README is wrong, should have trailing &#x27;-&#x27;: as in &quot;cat pcg_basic.c pcg32-demo.c | tcc -run -&quot;
jacobolusover 4 years ago
Here’s a Javascript implementation,<p><a href="https:&#x2F;&#x2F;observablehq.com&#x2F;@jrus&#x2F;permuted-congruential-generator" rel="nofollow">https:&#x2F;&#x2F;observablehq.com&#x2F;@jrus&#x2F;permuted-congruential-generat...</a><p>It’s a bit of a pain because Javascript can’t do native 64-bit integer arithmetic. But it should still be fast enough for most purposes.
nimishover 4 years ago
Vigna&#x27;s RNGs are faster and as good statistically so it&#x27;s not clear why you&#x27;d use PCG.<p>They are a neat theoretical construction however I believe they have some serious flaws when attempting to split and construct multiple streams.<p>Honestly though RDRAND is cheap enough that I&#x27;d take true randomness over determinism.
whateveracctover 4 years ago
And there are Haskell bindings: <a href="https:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;pcg-random" rel="nofollow">https:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;pcg-random</a><p>Nice!
mshachkovover 4 years ago
One might be interested in <a href="https:&#x2F;&#x2F;github.com&#x2F;wangyi-fudan&#x2F;wyhash" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;wangyi-fudan&#x2F;wyhash</a>
评论 #24799844 未加载
Tipewryterover 4 years ago
For &quot;Arc4Random&quot; it says &quot;Reproducible Results: Not Always&quot;.<p>Can an algorithm really produce a non-reproducible result?
评论 #24785612 未加载
评论 #24785687 未加载
评论 #24785579 未加载
luciopercaover 4 years ago
Sounds pretty undecidable to me to proof that a pseudo number generator has a challenging prediction difficulty.
dragontamerover 4 years ago
The pcg-random methodology is very good. The basis is the following pattern:<p>#1: Have a &quot;counter&quot; of some kind. The simple counter trivially creates a maximum length cycle. &quot;seed++&quot; is one such counter.<p>#2: Have a &quot;hash&quot; that converts the counter into a random number, using a 1-to-1 bijection. There are a great many 1-to-1 bijections.<p>So your RNG is basically:<p><pre><code> oldSeed = seed; seed = counterFunction(seed); return hash(oldSeed); </code></pre> ------------<p>I used this methodology to make a pretty fast generator myself. The coding was done in a weekend, but it took some weeks to test: <a href="https:&#x2F;&#x2F;github.com&#x2F;dragontamer&#x2F;AESRand" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dragontamer&#x2F;AESRand</a><p>For AESRand:<p>&quot;counterFunction&quot; is a SIMD 2x64-bit Add over the XMM register. I chose an odd number arbitrarily (which are just the first 16 prime numbers: 0x01030507...), which will trivially cycle after 2^64 numbers.<p>&quot;hash&quot; is aesenc(aesenc(seed, constant), constant), where constant is an arbitrary (chosen to be the same odd number that was used in the &quot;counterFunction&quot; step). The 2nd parameter to aesend is just an XOR.<p>I also run a 2nd parallel aesdec(aesenc(seed, constant), constant) to generate a 2nd set of 128-bit random numbers, for 256-bits to be made across the hash. Yes, a 128-bit seed &quot;hashes&quot; into a 256-bit random number. Since this passes statistical tests, its probably fine, and this is a good source of instruction-level-parallelism.<p>All in all, I achieved 30GB&#x2F;sec random numbers. Or 256-bits of random numbers every 3.7 cycles that passes BigCrush, TestU01, and PractRand.<p>--------<p>AES is a 1-to-1 bijection: that&#x27;s a necessary condition for AES to be decoded. Though I use AES, this function is NOT cryptographically sound. I&#x27;m just using AES because its the fastest high-quality bijection in the entire modern CPU instruction set. x86, ARM, and POWER9 all implement single-cycle AES instructions.<p>It is possible to write a portable AESRand across the different CPUs (ARM, x86, and POWER9). I got far enough to prove that its possible, but then my real work started to ramp up and I had to drop this hobby project. Its very tricky to do so: ARM, x86, and POWER9 implement AESENC slightly differently: shuffling the fundamental steps in different ways.<p>Or in the case of POWER9, it executes in big-endian mode instead of little-endian (like ARM &#x2F; x86). Redesigning the algorithm to be portable across the shuffled &quot;SubBytes&quot; and &quot;MixColumns&quot; steps between the CPUs is tricky but possible.
tshoaibover 4 years ago
Would the outputs of these algorithms be considered pseudo-random?
s9wover 4 years ago
The Drama between the author of PCG (u&#x2F;ProfONeill) and the author of xoshiro (u&#x2F;sebastianovigna) is one of the more entertanining parts of the C++ community. Too bad that despite that fierce competition, the &lt;random&gt; standard header itself is universally hated.
评论 #24788455 未加载
评论 #24786174 未加载
评论 #24785598 未加载