SeedChance.

Got a problem with OpenTTD? Find some help here.

Moderator: OpenTTD Developers

Post Reply
erichuff
Engineer
Engineer
Posts: 1
Joined: 25 Aug 2019 16:23

SeedChance.

Post by erichuff » 25 Aug 2019 16:32

Hi everyone!

Im playing around with the town name generator, trying to add spport for real danish town names. I have got it to work, but i do not understand the SeedChance function entirely.

The syntax could be like this:

SeedChance(0, 15, seed);

This should generate a random number between 0 and 15 from the unique town seed. But i dont understand what this does:

SeedChance(5, 15, seed); ? What difference does it make to use for example 5 instead of zero in the shift_by variable?

Thanks.

User avatar
jfs
Director
Director
Posts: 562
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: SeedChance.

Post by jfs » 25 Aug 2019 16:59

Shifting the seed by a different amount picks out a different part of value. If different parts of the town name should be non-correlated then the shift should be different.

In specific, the town names are generated from a 32 bit seed, and the SeedChance function picks out 16 bits offset by shift_by from that 32 bit number, then scales it into the range given by the max parameter. So you have only two strictly entirely uncorrelated values possible from the seed (shift 0 and 16), but in practice you have more, depending on the max given. On the other hand, it's difficult to exploit the lower 12 or so bits of the seed value using just the SeedChance function.

Post Reply

Return to “OpenTTD Problems”

Who is online

Users browsing this forum: Google Adsense [Bot] and 3 guests