News for hackers. Stuff that matters.
Re:Should random() be banned? by SomeCallMeTim on Thursday February 11, 2021 @04:02PM (#26107116)
Actually, in my experience using the default random implementation in games:

* It's not fast enough. * It has patterns that can be seen if you are using it to, for instance, generate 2d noise.

So for games you'd typically use, say, the Mersenne Twister [1], which is faster (amortized) and is distributed evenly across 623 dimensions. [2]

It's not cryptographic, but it's far better for games. If you're not going to have a crypto default random, better to at least have a really good and really fast one.

[1] https://en.wikipedia.org/wiki/Mersenne_twister

[2] http://www.math.sci.hiroshima-u.ac.jp/m-mat/MT/ARTICLES/mt.p...

Re:Should random() be banned? by patrec on Thursday February 11, 2021 @06:10PM (#26108746)
Mersenne Twister is the MD5 of random number generators: it's neither secure nor fast (and unlikely md5 not space-efficient, or simple to implement either). You can have something that has better randomness, runs several times faster, uses less space and has a much more compact and simple implementation.

So given that Mersenne Twister sucks in pretty much every possible way other than having a catchy name, likely the sole source of its continued popularity, its probably not a good choice for replacing some "default" random number generator with something better.

Re:Should random() be banned? by MauranKilom on Thursday February 11, 2021 @07:45PM (#26109537)
> You can have something that has better randomness, runs several times faster, uses less space and has a much more compact and simple implementation.

Could you share at least one example of such a generator?

Most of these aspects are trivial to improve on, but having "better randomness" on top is quite the bar.

Re:Should random() be banned? by ChrisLomont on Thursday February 11, 2021 @08:35PM (#26109852)
The PCG class of PRNGs are very good, and have a zillion tunable versions to suit every need.

https://www.pcg-random.org/index.html

Re:Should random() be banned? by sobriquet9 on Thursday February 11, 2021 @10:09PM (#26110359)
Re:Should random() be banned? by patrec on Friday February 12, 2021 @01:37AM (#26111258)
https://en.wikipedia.org/wiki/Mersenne_Twister#Alternatives

https://nullprogram.com/blog/2017/09/21/

I don't think better randomness than MT is as high a bar as you make it out to be, both links above also briefly mention statistical shortcomings of MT.

Re:Should random() be banned? by Khaine on Thursday February 11, 2021 @09:50PM (#26110245)
Doesn't FreeBSD use Mersenne Twister as its CSRNG?
Re:Should random() be banned? by fanf2 on Friday February 12, 2021 @08:30AM (#26113392)
No, FreeBSD uses Fortuna https://en.wikipedia.org/wiki/Fortuna_(PRNG)

Mersenne Twister is not secure, and it isn’t a very good RNG even for insecure uses.

Re:Should random() be banned? by Khaine on Friday February 12, 2021 @04:34PM (#26118808)
Thanks! I don't know why I thought they used it.
Re:Should random() be banned? by bigiain on Thursday February 11, 2021 @10:38PM (#26110511)
Patterned random numbers become a feature in some games, even if an unintentional one.

I used to be able to play about a dozen Pac-Man levels knowing exactly where every ghost was going to go and every bonus that was going to appear. And I wasn’t a very good player.

Pac-Man would have been a less fun game for many people if it used crypto grade random.

Re:Should random() be banned? by watwut on Friday February 12, 2021 @02:58AM (#26111564)
Pac-Man ghosts did not moved all that much randomly. Each ghost had special follow up strategy. You likely learned their movement patterns without realizing it.