Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I intend to use the Mersenne twister to generate a level using a seed , but I also want to make fixed levels, so for now I'm using XML to store data of the level (~40 numbers).

However, it would be awesome if I could get the seed of a specific level by reversing the process.

I guess if I used my own pseudo-random number generator I possibly could do it, but my question is can I do it with the Mersenne twister?

Here is an example of what I want to do:

If the seed 1234 gives output 25 65 78 01, can I get the seed 1234 knowing only the generated output?

Thanks in advance! (For those who wonder why I'd want to do this; my XML parsing is a lot slower than generating a level, plus XML files are bigger than seed numbers.)

share|improve this question
1  
AFAIK, it's not physically possible except by brute force. Why not just store the seed? –  The Communist Duck Jun 18 '11 at 9:22
    
because i cant determine a fixed level with fixed values using seed (except brute force too) –  eephyne Jun 18 '11 at 9:27
    
I am confused by 'fixed level'. Usually that refers to a level that is not randomly generated. So you are generating a level with a seed X and getting the first 40 numbers for it..why can you not store the seed when you generate? –  The Communist Duck Jun 18 '11 at 9:29
    
there are two kind of levels i use , those who are generated by seed , and those who i name "fixed" , wich are writed by myself with each values determined individually and not using any computing. –  eephyne Jun 18 '11 at 9:36
2  
I personally do find this interesting. It's like compressing an entire level into one number! It reminds me a bit of spline fitting - if you have a set of points in 2D, you can try to fit them along a spline and then just store the parameters of the spline which might be fewer than the points themselves. I've considered this for terrain generation, for example; instead of storing a heightmap, just store a set of 3D splines which can then generate the necessary terrain points on-the-fly. I don't know if this is done anywhere currently. –  Ricket Jun 18 '11 at 15:45
show 9 more comments

3 Answers

up vote 7 down vote accepted

No, you cannot get a seed for a sequence of numbers that you have created yourself. You could possibly get a seed from a sequence of generated numbers by brute force.

Coincidentally, in the infinite monkeys writing Shakespeare way, if you used large enough seed numbers, you probably could find a seed that generates your sequence, but linearly searching for one specific number in the range of (potentially) a 256bit or greater integer is not possible in a real time.

I do not see why you are needing to store 40 numbers in an XML file. Why not use a text file? Heck, why not hardcode them into an array?

share|improve this answer
    
i said 40 numbers for indicating an average number of random number used. the xml is more complex . i admit , that was not very clear –  eephyne Jun 18 '11 at 12:24
add comment

In general, no, you can't do that. Random number generators are one way functions from the current seed to the value.

A simple thought experiment should clarify why you can't do this. Say you're using your random number generator to generate the numbers for a level like 25 65 78 01. Lets say your seed is a four digit number and each of those levels is a two digit number. Given that, there's 100,000,000 possible different levels but only 10,000 different seeds. Obviously each level can't have its own unique seed then, there aren't enough to go around.

share|improve this answer
    
and if i don't care about the seed length ? –  eephyne Jun 20 '11 at 8:21
    
Then just store all of the level data directly and call it the "seed". –  munificent Jun 21 '11 at 0:18
add comment

In case this wasn't obvious from @Communists' answer: there is no reason every level needs to be stored in the same format.

If you want to store your hand-made levels by storing every detail, but store your randomly-generated levels by only storing the seed, that's fine. Just add a parameter in the level-file describing which it is eg. <level type="random" seedvalue="1234567890">

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.