Hi,
I guess these won't work within Grimrock as they don't belong to the math category?
I am doing some random number generation and would need a good seed for the math.randomseed function but the above doesn't seem to be implemented.
Thanks.
[SCRIPT] LUA os.clock() and os.time()
[SCRIPT] LUA os.clock() and os.time()
Last edited by YpsiNine on Fri Oct 12, 2012 7:24 pm, edited 1 time in total.
Re: LUA os.clock() and os.time()
.
I came up with a solution of my own, yay!
The result is a random seed, but not as huge as os.clock() or os.time() would give I suppose, but it's better than nothing.
If you simply do random without a seed there will be very bad variation, like this:
Will typically produce:
3
3
3
1
3
3
3
3
Now with my code however, more randomness is to be expected.
Will typically produce:
2
3
1
1
2
3
1
2
Use the function for example like this:
I came up with a solution of my own, yay!
The result is a random seed, but not as huge as os.clock() or os.time() would give I suppose, but it's better than nothing.
If you simply do random without a seed there will be very bad variation, like this:
Code: Select all
math.random(1,3)3
3
3
1
3
3
3
3
Now with my code however, more randomness is to be expected.
Code: Select all
function randomize(x, y)
seed = spawn("dagger", 1, 1, 1, 1) --spawns a dagger at a place where the party can't interfere
math.randomseed(seed.id) --uses the ID of the spawned dagger as a random seed
result = math.random(x, y) --here we do the random number generation
print(result) --to see the number it picked while debugging, else just remove this line
print(seed.id) --to see the seed it got while debugging, else just remove this line
seed:destroy() --then we destroy the dagger
return result --we need to return the result to whatever asks for it
end2
3
1
1
2
3
1
2
Use the function for example like this:
Code: Select all
variable = randomize(1,3)
if variable == 1 then
hudPrint("I got a 1")
elseif variable == 2 then
hudPrint("I got a 2")
elseif variable == 3 then)
hudPrint("I got a 3")
endRe: [SCRIPT] LUA os.clock() and os.time()
Bump if someone wants to include this script in the Useful scripts repository thread.
Re: [SCRIPT] LUA os.clock() and os.time()
I think it's good to add it there because it's quite unique and will surely be useful in the future - you can just add a post to that thread yourself and put it in
Finished Dungeons - complete mods to play
Re: [SCRIPT] LUA os.clock() and os.time()
Ok, done.Komag wrote:I think it's good to add it there because it's quite unique and will surely be useful in the future - you can just add a post to that thread yourself and put it in
