Dominion Strategy Forum

Please login or register.

Login with username, password and session length
Pages: [1]

Author Topic: How to make a pseudorandom number generator act the same but different  (Read 1870 times)

0 Members and 1 Guest are viewing this topic.

sudgy

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3431
  • Shuffle iT Username: sudgy
  • It's pronounced "SOO-jee"
  • Respect: +2707
    • View Profile
0

I wanted to put more in the title, but it didn't fit :-\

Anyway, I'm making a game that will have an infinite overworld (think of minecraft's infinity).  I want a given world to be reproducible, but the problem is that it will only generate the world in chunks.  How could you make the randomness reproducible given a single seed but everything could be done out of order?
« Last Edit: September 11, 2015, 09:22:03 pm by sudgy »
Logged
If you're wondering what my avatar is, watch this.

Check out my logic puzzle blog!

   Quote from: sudgy on June 31, 2011, 11:47:46 pm

Ghacob

  • Young Witch
  • ****
  • Offline Offline
  • Posts: 149
  • Shuffle iT Username: Gender
  • J. They/them
  • Respect: +204
    • View Profile
Re: How to make a pseudorandom number generator act the same but different
« Reply #1 on: September 11, 2015, 09:26:07 pm »
0

Note: I have no experience in this

You would probably have to tie the seed based chunk generation to location. One way I can think of doing that so that it's infinitely reproducable is to plug the seed as well as chunk coordinates into the pseudorandomizer. This would require setting some origin point (Hey, that's what minecraft does!)
I don't actually have any idea how you'd put this into practice but that's my thoughts on the things
Logged
Gender happened.

pubby

  • Minion
  • *****
  • Offline Offline
  • Posts: 548
  • Respect: +1046
    • View Profile
Re: How to make a pseudorandom number generator act the same but different
« Reply #2 on: September 11, 2015, 09:32:11 pm »
0

Hash the chunk coordinate and xor it with a starting seed. Use noise functions if you want smooth transitions between chunks.
Logged

sudgy

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3431
  • Shuffle iT Username: sudgy
  • It's pronounced "SOO-jee"
  • Respect: +2707
    • View Profile
Re: How to make a pseudorandom number generator act the same but different
« Reply #3 on: September 11, 2015, 09:33:57 pm »
0

Note: I have no experience in this

You would probably have to tie the seed based chunk generation to location. One way I can think of doing that so that it's infinitely reproducable is to plug the seed as well as chunk coordinates into the pseudorandomizer. This would require setting some origin point (Hey, that's what minecraft does!)
I don't actually have any idea how you'd put this into practice but that's my thoughts on the things

The problem is, how would I plug the chunk coordinates into the randomizer?  I can't just do something stupid like "world seed + chunk x + chunky"*12 because then a lot of the chunks would have the same seed.

Actually, giving all of the chunks an id in clockwise order (or something similar) from the origin and then just making the chunk seed "world seed + chunk id" could work.  Yay, I just solved my own problem!  If anybody else wants to suggest something better you can.

*I know it says chunky, that was an accident and I kept it.

1I couldn't decide if I wanted to put the * before or after the quotes.  Sorry if I ruined anybody's life with possibly poor grammar.

2And, after using the *, I realized I couldn't use a ** to denote a second footnote, so now I'm mixing footnote calls.


PPE:

Hash the chunk coordinate and xor it with a starting seed. Use noise functions if you want smooth transitions between chunks.

I'm just doing this in Python and am not too familiar with technical terminology for random number generators.  How would I go about doing this?


EDIT: This is the messiest post I have ever seen.
« Last Edit: September 11, 2015, 09:40:02 pm by sudgy »
Logged
If you're wondering what my avatar is, watch this.

Check out my logic puzzle blog!

   Quote from: sudgy on June 31, 2011, 11:47:46 pm

pubby

  • Minion
  • *****
  • Offline Offline
  • Posts: 548
  • Respect: +1046
    • View Profile
Re: How to make a pseudorandom number generator act the same but different
« Reply #4 on: September 11, 2015, 09:46:59 pm »
0

I don't know python so I'm probably no help, but in other languages I would store the chunks coordinates as a pair of 32 bit integers, and then the chunk seed would be a 64 bit integer:
Code: [Select]
(chunk_coord.x | (chunk_coord.y << 32)) ^ initial_seedor something like that
Logged

Jack Rudd

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1325
  • Shuffle iT Username: Jack Rudd
  • Respect: +1384
    • View Profile
Re: How to make a pseudorandom number generator act the same but different
« Reply #5 on: September 13, 2015, 09:54:08 am »
0

I remember using BASIC to generate random numbers, and the way to get different ones each time was to put in RANDOMIZE TIMER.
Logged
Centuries later, archaeologists discover the remains of your ancient civilization.

Evidence of thriving towns, Pottery, roads, and a centralized government amaze the startled scientists.

Finally, they come upon a stone tablet, which contains but one mysterious phrase!

'ISOTROPIC WILL RETURN!'

Titandrake

  • Mountebank
  • *****
  • Offline Offline
  • Posts: 2210
  • Respect: +2856
    • View Profile
Re: How to make a pseudorandom number generator act the same but different
« Reply #6 on: September 16, 2015, 07:20:51 pm »
0

For Python at least, the built-in random library lets you set the seed manually. So, given a single seed for the world, you can call random.seed(<seed for that location>) before generating the terrain type/items for that location.

Based on reading the documentation, you can set the seed to any hashable object, so you can even call random.seed('some crazy string'), or random.seed( (<starting seed>, x, y) ) since tuples are also hashable. Internally I would guess Python calls hash() on the argument and uses that on the seed.
« Last Edit: September 16, 2015, 07:22:13 pm by Titandrake »
Logged
I have a blog! It's called Sorta Insightful. Check it out?
Pages: [1]
 

Page created in 0.064 seconds with 20 queries.