I'm interested in designing a game with a randomly-generated world. I'd like the world to be generated from a seed value, so that players could share these seeds among each other and play in the same world. What I'm not clear about is how to properly derive multiple independent world variables from the same seed, without players being able to deduce one facet from another. For example:

Fairy fruit is (n % 3): 0: delicious: 1: disgusting: 2: poisonous

The Troll King's heart is in his (n % 6): 0: skull 1: left elbow 2: right knee 3: left ankle 4: chest (cavity) 5: chest (loot)

The problem is, the player can deduce down to two possibilities where the Troll King's heart is by force-feeding a peasant some fairy fruit and watching the reaction. Likewise, if he's already fought the Troll King, he knows whether fairy fruit is safe to eat.

One workaround I thought of is to have each of those modulo values be a different prime number, which if I understand math would mean that you couldn't guess one value from another. But this would break if I wanted a non-prime number of options. In the Troll King example above, I'd have to remove one of the options, add another option, or make 6 a duplicate of an existing option and accept a non-uniform distribution. Does anyone have a better idea of how to do this?


1 Answer 1


Most games and applications solve this problem by using a pseudorandom number generator (PRNG). With a PRNG, your initial, sharable seed value is used to generate a sequence of numbers whose properties approximate the properties of sequences of random numbers which are then used as needed to generate your content and determine the outcomes of random events.

So using your example, one would not be able to deduce where the Troll King's heart is by force-feeding a peasant some fairy fruit and watching the reaction because each fairy fruit, as well as the location of the heart would be determined by a different random number.

It's a little bit more work if you want the outcomes of events to be independent of order. For instance, if you want a system in which fairy fruit has only a single outcome for a seed regardless of when or how often it is consumed, but that probably justifies its own post.

  • \$\begingroup\$ Thanks, that sounds like what I need. If I can spin one seed into an unlimited number of deterministic-but-unpredictable numbers, I can modulo one for the fruit (they should all have the same effect), one for the king, one for the number of dungeons, and so on for the locations of monsters, features, and so forth, without the user ever being able to deduce one detail from another. The idea is that the entire world be generated at the start of the game, so order of exploration wouldn't matter, since everything would already be set in stone. \$\endgroup\$
    – Evan Kaye
    Jun 23, 2021 at 16:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .