Page 1 of 3

Proper random number generation and radian/degree.

Posted: Tue Nov 18, 2008 3:34 pm
by MHD
I have noticed that Löve uses the default pseudo-random number generator. I suggest that you in the next versions implement a proper random generation (avilable somewhere on lua.org). Also I suggest that you take a stand point and decide to either convert all Löve functions to radians or all lua functions to degrees (this can be done at loadup manually, but...).

Re: Proper random number generation and radian/degree.

Posted: Tue Nov 18, 2008 3:42 pm
by rude
Well, you are quite the suggestionist[1], aren't you? ;)

You must have an average of two-three suggestions per day or something. :D

[1] Probably not a word.

Re: Proper random number generation and radian/degree.

Posted: Tue Nov 18, 2008 4:37 pm
by u9_
I think we brought up the degrees-vs-radians in another thread. One thing that kinda bugs me is rotations seem to be clock wise for increasing degrees. For a mathematician this is a little "upside-down", but it's easily solvable with a - in front :)

I would like to know what is the difference with the "proper" random generator and the pseudo random generator... specifically, when is it not a pseudo random generator. Afaik, there exist only pseudo random generators on computers, because they are deterministic.

Re: Proper random number generation and radian/degree.

Posted: Tue Nov 18, 2008 7:29 pm
by subrime
I think the conventional understanding is that a pseudo-random function will use a deterministic function to supply the same sequence of pseudo-random numbers every time it is reset, while a (non pseudo) random function will use a deterministic function with a changing seed (such as the current system time) to supply a different sequence of pseudo-random numbers each time it is reset.

As for radian and degrees, I think it unwise to change the behaviour of the standard lua math functions as people already accustomed to coding with lua/c/any-decent-language could easily be caught off guard.

Re: Proper random number generation and radian/degree.

Posted: Wed Nov 19, 2008 6:28 am
by tido
May I humbly suggest that we implement the multiply-with-carry pseudo-random number generator? According to G. Marsaglia, it is better than Mersenne twister (current favorite) because it's fast AND provides better period. You can read about it here: http://en.wikipedia.org/wiki/Multiply-with-carry

Re: Proper random number generation and radian/degree.

Posted: Wed Nov 19, 2008 11:06 am
by mike
I think the nerd factor of this forum just spiked. Discussing the random number generator we should use. That's pretty hardcore.

Re: Proper random number generation and radian/degree.

Posted: Wed Nov 19, 2008 3:50 pm
by u9_
subrime wrote:I think the conventional understanding is that a pseudo-random function will use a deterministic function to supply the same sequence of pseudo-random numbers every time it is reset, while a (non pseudo) random function will use a deterministic function with a changing seed (such as the current system time) to supply a different sequence of pseudo-random numbers each time it is reset.
So we just need to add math.randomseed( os.time() ) at the beginning of each program?
mike wrote:I think the nerd factor of this forum just spiked. Discussing the random number generator we should use. That's pretty hardcore.
I concur!

Re: Proper random number generation and radian/degree.

Posted: Wed Nov 19, 2008 4:05 pm
by rude
Lua will remain 100% standard and will not be changed. We'll have to change LÖVE if we want to change anything.

Re: Proper random number generation and radian/degree.

Posted: Thu Nov 20, 2008 3:23 am
by subrime
u9_ wrote: So we just need to add math.randomseed( os.time() ) at the beginning of each program?
Yes, that's the idea.

Re: Proper random number generation and radian/degree.

Posted: Fri Nov 21, 2008 3:10 pm
by surtic
Just a quick note - Lua's random number generator has problems with the first few numbers.

I suggest using

Code: Select all

math.random()
math.random()
math.random()
at the beginning of a program to get rid of these "bad" values.