bartbes wrote:You could even do awesome things like forking and then choosing one of the forks.
Since this thread is still kicking, would you mind giving an example of what you mean by this? Or a resource that explains what this means in greater detail? I think
Jasoco mentioned something that sounds similar, but I'd like to make sure I know what you mean.
Hexenhammer wrote:Code: Select all
math.randomseed(os.time())
randomNumber = math.random(1,100)
..will work just fine with LuaJIT's RNG. The new LÖVE RNG is pretty pointless now given that LuaJIT already addresses all common issues of the vanilla Lua one.
I know Slime just replied about this but I thought it's worth pointing out that he also stated that
"The love.math.random function exists partly because math.random's implementation is different on different operating systems. love.math.random will give the same results regardless of OS, given the same inputs (if the random seed/state is the same), but math.random will not."
Somebody else on the forums (I can't find what the exact response was) noted the implications of having RNGs that are dependent on OS by giving an example of generating a map on multiple OSs, and noting that - even though the same function is used to generate random data - the maps would end up different for people on different OSs because of math.random. Avoiding that seems to be the primary reason for making love.math.random.
This is coming from someone that barely knows how to use an RNG though, so take my rambling with a grain of salt.
Hexenhammer wrote:1. The seed value. os.time() is almost identical between calls, and unfortunately the most significant bits are identical . The strange vodoo done to the os.time() return value basically makes the bits which change more often the most significant ones.
So, hypothetically speaking, let's say I use a RNG to fetch 3 random numbers, with the following seeds: 1, 2, and 3. For the sake of the example, the returned numbers will be 3, 6, and 1. Then, I try to use the same RNG to fetch 3 random numbers again, with the seeds being 2, 3, and 4. Would I get completely different random numbers? Or would I get 6, 1, and a new random number?
I ask this because
one of Plu's posts makes it seem like the seed is the insertion point in a list of numbers, from which a number in this list is returned based on the seed. If that's the case, I could see why it's important to make the seed as random as the numbers returned from said list, and almost explains why you want to reverse os.time.
Why do I say almost? Because now I'm confused about
what Robin posted a while ago. In Robin's post, gen:setSeed(os.time()) is placed
outside of any function, yet the numbers are still always different! Since os.time is defined at the beginning, shouldn't it be a static value at that point (whatever os.time is when :setSeed is called)? And even if os.time as the argument is somehow dynamic
(seriously, if you guys say that os.time is a dynamic argument I'm going to dissolve into the floor), shouldn't the returned numbers be the same "random" number returned over and over until os.time changes (that is, until a second has passed)?
Robin even specifically stated that I
shouldn't be setting the seed inside of the function (and testing it myself has confirmed it):
Robin wrote:A function that returns or uses a pseudo-random number should not mess with the seed.
If the seed is an insertion point like I figure it is, why is it bad to change it wherever you want?
MY MIND IS IMPLODING.