[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Good random seeds.
- From: Petite Abeille <petite.abeille@...>
- Date: Thu, 15 May 2008 19:26:03 +0200
On May 15, 2008, at 7:03 PM, Jorge Visca wrote:
I was wondering what people use as seeds for the random generator.
os.time() seems ok, but the to-the-second precission and my usage
patterns make this a risky option. Not very probable, but when it
happens it means very weird behaviour.
If the quality of the PRNG is important to you, don't use math.random :)
Perhaps you would be better off with LHF's lrandom, a library for
generating random numbers based on the Mersenne Twister:
http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lrandom
I'm on linux, and the ideal would be lua only solution, with no extra
libraries. I could parse MAC adresses from runing "ifconfig", and hash
them. Or somehow get a number from /dev/urandom... Sadly, "date +%N"
doesn't work on my platform. Any ideas?
For the humble purpose of generating slowly changing string token, I
use a combination of math.random and hashing:
http://dev.alt.textdrive.com/browser/HTTP/Token.lua#L66
Those tokens are used as more or less random HTML form identifiers, to
slowdown spambots [1], e.g.:
<input type='text' name='dsr'
<textarea name='ojdmrdwtx'
<input type='hidden' name='faqn'
http://svr225.stepx.com:3388/main/editor
[1] http://nedbatchelder.com/text/stopbots.html