Page 2 of 3
Re: good seeding for math.random
Posted: Sun Feb 01, 2009 6:17 am
by osgeld
osuf oboys wrote:
Could you simplify this problem instance as much as possible and provide a demo? Are you sure that it is not due to some granularity of the velocities?
not that i am doubting anyone i tend to think the same
and no im not saying random is random, as far as i understand it there is no real random in computers, hince why 99% of the time you will see psudo rng listed, if nothing else to avoid debate, SO if you see constant patterns in your random numbers then i would assume something needs to be done to vary the humon perception of it
Re: good seeding for math.random
Posted: Sun Feb 01, 2009 10:03 pm
by invisisci
This works 100% for me:
Code: Select all
function load()
math.randomseed(os.time())
end
function update(dt)
local x = math.random(0, 500) --x will be a random integer 0-500 each run
end
Re: good seeding for math.random
Posted: Mon Feb 02, 2009 4:14 pm
by Tabasco
I briefly re-visited my old starfield thing yesterday and noticed that I apparently already fixed it and forgot about it. I use math.random all over the place so I'm not sure what I was thinking the other night. Apparently very little.
Re: good seeding for math.random
Posted: Tue Feb 03, 2009 3:23 am
by nunix
I'm working with the OP on some of this stuff.
Code: Select all
function load()
math.randomseed(os.time())
font = love.graphics.newFont(love.default_font, 12)
love.graphics.setFont(font)
message = math.random(1,9)
end
function draw()
love.graphics.draw(message, 100, 100)
end
This returns 8
every time. Why?!
Re: good seeding for math.random
Posted: Tue Feb 03, 2009 3:39 am
by osgeld
when i run it i get all sorts of results
(printing to command prompt (linux))
Code: Select all
6
4
7
7
8
6
1
4
6
5
7
4
4
1
4
7
7
9
6
8
2
3
8
8
7
4
5
7
6
1
3
3
4
9
9
2
6
1
6
3
6
4
7
9
4
1
7
2
1
3
9
3
5
8
1
3
2
5
1
8
5
3
1
9
2
1
2
8
1
7
1
7
1
7
7
4
8
4
6
9
7
6
2
3
4
2
5
6
7
6
4
2
8
4
2
1
4
3
8
5
9
9
3
1
7
9
5
6
4
1
5
1
6
6
4
9
7
9
5
4
5
9
6
3
4
7
3
7
9
2
3
9
2
5
9
8
5
4
4
8
5
8
9
1
4
4
1
2
3
6
5
7
5
2
1
8
8
4
6
8
5
9
7
6
5
7
4
9
QUIT love.system [Generic]
Re: good seeding for math.random
Posted: Tue Feb 03, 2009 3:41 am
by philnelson
I am wondering if this is possibly an OS X issue? Both nunix and I are running Mac OS X 10.5 intel.
Re: good seeding for math.random
Posted: Tue Feb 03, 2009 3:43 am
by osgeld
might be
Re: good seeding for math.random
Posted: Tue Feb 03, 2009 3:54 am
by philnelson
I get the same result: 8, every single time running it via the Love executable in OS X and Windows XP. On OS X I just double click test.love, on windows I click and drag test.love (which contains the main.lua file posted by nunix) onto the Love.exe. 8 every time.
Re: good seeding for math.random
Posted: Tue Feb 03, 2009 4:28 am
by Tabasco
Code: Select all
function load()
math.randomseed(os.time())
font = love.graphics.newFont(love.default_font, 12)
love.graphics.setFont(font)
message1 = math.random(1,9)
message2 = math.random(1,9)
message3 = math.random(1,9)
end
function draw()
love.graphics.draw(message1 .. "--" .. message2 .. "--" .. message3, 100, 100)
end
message1 is always 9 for me (Windows XP, haven't tried on linux yet), but message2 and message 3 are random.
No matter how many times I load it, the first number returned is always 9 for me.
If I increase the range on message1 to 1-500, it will be 10 for a minute, then 11, then 12, then 13, but ONLY on the first request. Everything after that seems fine.
After composing this I ran it again and it's up to 20, then 21.
There's a little bit written about it under the math.random(seed) section here:
http://lua-users.org/wiki/MathLibraryTutorial
Re: good seeding for math.random
Posted: Tue Feb 03, 2009 6:38 am
by philnelson
The Wiki helped, specifically this:
Code: Select all
-- Initialize the pseudo random number generator
math.randomseed( os.time() )
math.random(); math.random(); math.random()
-- done. :-)
Calling math.random() 3 or 4 times before I actually need it seems to give me the results I need. Very weird.