lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Overflow could be a problem in this algorithm?
If x became near MAX_INT, what happens on the next
multiplication ?

--- Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> escreveu:

> BTW, there's always a simple replacement for rand()
> suggested by Knuth,
> as quoted in Numerical Recipes:
> 
> do
> 	local x=0
> 	local a=1664525
> 	local c=1013904223
> 	function randomseed(s)
> 		x=s
> 	end
> 	function rand()
> 		x=a*x+c
> 		return x
> 	end
> end
> 
> http://www.library.cornell.edu/nr/bookcpdf/c7-1.pdf
> 
> This is suitable for 32-bit integers.
> 
> --lhf
> 


__________________________________________________
Faça ligações para outros computadores com o novo Yahoo! Messenger 
http://br.beta.messenger.yahoo.com/