Community documentation
Re: Community documentation
I added a new page listing the champion conditions and some info about them.
Re: Community documentation
I made an entry for MersenneTwister:
- MersenneTwister.create(seed)
Returns an instance of MersenneTwister required to generate random numbers. Seed is a number.
e.g. local random = MersenneTwister.create(Time.systemTime()) - MersenneTwister.random()
Generates a random real number between 0 and 1.
e.g. local n = random:random() - MersenneTwister.randomInt(min, max)
Generates a random integer between the given numbers min and max.
e.g. local n = random:randomInt(1, 10) produces a random integer from 1 to 10
e.g. MersenneTwister.randomInt(MersenneTwister.create(Time.systemTime()), 1, 10) will also return a random integer from 1 to 10
Last edited by Batty on Sun Jan 11, 2015 2:34 am, edited 1 time in total.
Re: Community documentation
MersenneTwister is used once in the original dungeon:
Code: Select all
function initMimics()
local skipLevels = {
31, -- shipwreck beach
32, -- dead sailor's cave
19, -- twigroot forest
20, -- twigroot tunnels
21, -- twigroot basement
22, -- forgotten river
}
-- find all chests except in first three levels
local chests = {}
for i=1,Dungeon.getMaxLevels() do
if not table.contains(skipLevels, i) then
for e in Dungeon.getMap(i):allEntities() do
if e.chest then
chests[#chests+1] = e.chest
end
end
end
end
--print(#chests.." found")
-- place random mimics
local count = 0
local random = MersenneTwister.create(Time.systemTime())
for i=1,8 do
local n = random:randomInt(1, #chests)
local chest = chests[n]
if chest then
--print(chest.go.x, chest.go.y, chest.go.level)
chest:setMimic(true)
table.remove(chests, n)
count = count + 1
end
end
--print(count.." mimics placed")
end
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Community documentation
Why did they even bother to put that in there?minmay wrote:MersenneTwister is used once in the original dungeon:
Re: Community documentation
AFAIK MersenneTwister should produce a more random random number than math.random() does, i.e. closer to being truly random.Thorham wrote:Why did they even bother to put that in there?
Re: Community documentation
From a modding perspective the main advantage of MersenneTwister over calling math.random() is that you can control the state. As far as I know, you cannot create your own instance of the generator used for math.random and its internal state can change in various ways you can't control because Grimrock calls it internally (just try saving/loading a game). An instance of MersenneTwister will only advance when you advance it. So a player saving/loading won't change the next numbers to be generated. This could be important if you're, say, generating a random level on the fly, and don't want the player to be able to savescum to get different levels.
The quality of the random numbers is probably better as well, but in most modding applications this is not noticeable (and Mersenne Twister is relatively easy for an end user to predict the state of, so if that's an issue you'll need a more complicated PRNG than either one anyway).
The quality of the random numbers is probably better as well, but in most modding applications this is not noticeable (and Mersenne Twister is relatively easy for an end user to predict the state of, so if that's an issue you'll need a more complicated PRNG than either one anyway).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Community documentation
Good point.minmay wrote:From a modding perspective the main advantage of MersenneTwister over calling math.random() is that you can control the state.