Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Perhaps there is a reason why software like Lua, Python, and Ruby all include their own implementation of a Mersenne Twister.

As far as I know, Lua does not include Mersenne Twister. math.random() is just C rand().



This is correct for the standard Lua interpreter [0].

LuaJIT bundles its own Tausworthe PRNG [1].

————

0. http://www.lua.org/manual/5.2/manual.html#pdf-math.random

1. http://luajit.org/extensions.html#math_random


I've noticed that Ruby's RNG is not that great. I've got a couple of small IRC bot scripts, one is a dice roller, the other is one that takes random items from a Google spreadsheet (using simple Random#rand in the first case, and Array#sample in the second).

The dice seems biased to certain numbers, and the spreadsheet has the same items come up more than mundane statistics would otherwise suggest. (A 1/50 roll landing on the same item 2-3 times in a row, multiple times per day?)

It's gotten to the point where my users don't want to use my bot for RPGs. I'll have to see if using SecureRandom#random_number produces any different results


Also MT still has to be seeded, it is not crypto-safe and its quality/computational load ratio is not too good.


It's far more complex than it needs to be. If you want a fast, high quality deterministic RNG, use something from the xorshift family.


This is a good article describing fast non-cryptographic RNGs: http://www.drdobbs.com/tools/fast-high-quality-parallel-rand... http://www.drdobbs.com/tools/fast-high-quality-parallel-rand...

CMRES is quite impressive, I get ~1500 MB/s out of it. Quite useful for generating large unique files for various testcases.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: