Eternity

Show off your games, demos and other (playable) creations.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Eternity

Post by thelinx »

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)))
Not that has anything to do with anything. Also, why not just randomseed(os.time())?
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Eternity

Post by slime »

thelinx wrote:
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)))
Not that has anything to do with anything. Also, why not just randomseed(os.time())?
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.

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)) )
linux-man
Citizen
Posts: 67
Joined: Thu Apr 28, 2011 4:51 pm

Re: Eternity

Post by linux-man »

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.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Eternity

Post by Jasoco »

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?

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
This is what I get on OS X:

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
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: Eternity

Post by bmelts »

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.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Eternity

Post by Jasoco »

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?
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Eternity

Post by TechnoCat »

I recommend you further your discussion on PRNG here: https://bitbucket.org/rude/love/issue/3 ... ality-prng
User avatar
miloguy
Prole
Posts: 32
Joined: Sat Jul 02, 2011 2:09 am

Re: Eternity

Post by miloguy »

Code: Select all

ship.lua:91: attempt to index field 'dock' (a nil value)
D: It sounds so cool
linux-man
Citizen
Posts: 67
Joined: Thu Apr 28, 2011 4:51 pm

Re: Eternity

Post by linux-man »

:x
miloguy wrote:

Code: Select all

ship.lua:91: attempt to index field 'dock' (a nil value)
D: It sounds so cool
What happens to you is caused by this random randomness we're talking about.

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).
User avatar
SoggyWaffles
Citizen
Posts: 72
Joined: Sun Jan 02, 2011 3:27 am
Location: Wyoming, USA

Re: Eternity

Post by SoggyWaffles »

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
Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests