Not that has anything to do with anything. Also, why not just randomseed(os.time())?slime wrote:This was recommended in the lua-users site as a randomseed generator for Mac OSX (put it at the top of love.load or something).Code: Select all
math.randomseed(tonumber(tostring(os.time()):reverse():sub(1,6)))
Eternity
Re: Eternity
- slime
- Solid Snayke
- Posts: 3162
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Eternity
Apparently the Mac OS X random thingie doesn't work quite as well as in other operating systems, os.time() may produce predictable results. I thought this might be the problem he's having.thelinx wrote:Not that has anything to do with anything. Also, why not just randomseed(os.time())?slime wrote:This was recommended in the lua-users site as a randomseed generator for Mac OSX (put it at the top of love.load or something).Code: Select all
math.randomseed(tonumber(tostring(os.time()):reverse():sub(1,6)))
Why math.random() might give weird results on OSX and FreeBSD?
*...The problem seems to be that when the seeds differ very little the first value of generated by BSD rand() also differ very little. This difference is lost when Lua converts the integer returned by rand() into a real number, effectively preserving only the high bits in the result. When you call math.random(1,100) from Lua, the low-bit difference vanishes and you see the same integer result.
-- improve seeding on these platforms by throwing away the high part of time,
-- then reversing the digits so the least significant part makes the biggest change
-- NOTE this should not be considered a replacement for using a stronger random function
-- ~ferrix
math.randomseed( tonumber(tostring(os.time()):reverse():sub(1,6)) )
Re: Eternity
Most of the time I use pre-defined random numbers by choosing the same seed. Math.randomseed(512) on Mac X give me different results, so I'm working on a pure lua random generator.
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Eternity
I just tested using a specific Random Seed on both OS X and Windows 7 and then generating 25 numbers randomly chosen between 1 and 10, and they were different sets of numbers.
Does that mean if I saved the seed I use and someone uses the same seed in my game on another platform, it's going to behave completely differently? Can OS X and Windows and Linux not have the same number generator? How does Java work so that Minecraft's seeds always look the same on each platform? Imagine the outcry if OS X's version of "gargamel" was a vast flat wasteland instead of all high mountains and valleys.
Here's some code to sample. What random numbers do you get on your OS?
This is what I get on OS X:
Does that mean if I saved the seed I use and someone uses the same seed in my game on another platform, it's going to behave completely differently? Can OS X and Windows and Linux not have the same number generator? How does Java work so that Minecraft's seeds always look the same on each platform? Imagine the outcry if OS X's version of "gargamel" was a vast flat wasteland instead of all high mountains and valleys.
Here's some code to sample. What random numbers do you get on your OS?
Code: Select all
math.randomseed(100) math.random() math.random() math.random()
function love.load()
v = {}
local str = ""
for i=1,25 do
v[i] = (math.random(1,10))
str = str .. v[i] .. " "
end
print(str)
end
function love.update(dt) end
function love.draw()
for i=1,25 do
love.graphics.setColor(255,255,255)
love.graphics.rectangle("fill", 10 + 20 * i, 10, 18, 14)
love.graphics.setColor(0,0,0)
love.graphics.printf(v[i], 10 + 20 * i, 10, 18, "center")
end
end
Code: Select all
9 3 9 8 9 10 5 4 10 1 5 4 10 2 8 4 7 8 7 9 1 7 7 2 4
Re: Eternity
The difference here is the RNG. Lua's math.random uses the underlying system's C rand() function, which is implementation-dependent. As you've seen, Windows 7's version is different from Mac OS X's. Java, on the other hand, uses the same RNG algorithms across all systems, so you get consistent results with a given seed no matter which OS you run Minecraft on.
This behavior can be remedied by using an alternate RNG that is implementation-independent - a Mersenne Twister, for instance.
This behavior can be remedied by using an alternate RNG that is implementation-independent - a Mersenne Twister, for instance.
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Eternity
Would that be useful for Löve? Or should I just plan ahead to warn users that any procedurally generated levels that my game might generate won't work across platforms?
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: Eternity
I recommend you further your discussion on PRNG here: https://bitbucket.org/rude/love/issue/3 ... ality-prng
Re: Eternity
Code: Select all
ship.lua:91: attempt to index field 'dock' (a nil value)
Re: Eternity
What happens to you is caused by this random randomness we're talking about.miloguy wrote:D: It sounds so coolCode: Select all
ship.lua:91: attempt to index field 'dock' (a nil value)
I think I have an answer. Look at http://love2d.org/forums/viewtopic.php?f=5&t=3424.
Now, good night (is almost morning here).
- SoggyWaffles
- Citizen
- Posts: 72
- Joined: Sun Jan 02, 2011 3:27 am
- Location: Wyoming, USA
Re: Eternity
Not sure if this has been mentioned (lots of posts in here), but your framebuffers are not Po2. Well, at least one of them, won't run on most older hardware.
"Beneath the clouds lives the Earth-Mother from whom is derived the Water of Life, who at her bosom feeds plants, animals and men." ~Larousse
Who is online
Users browsing this forum: Bing [Bot] and 10 guests