(Untitled)

Aug 19, 2006 00:26

Does anyone know of an algorithm for generating a series of numbers such that any number in the series can be plugged into the alrogithm to get the next number in the series in either direction?

Leave a comment

Comments 8

omnifarious August 19 2006, 07:59:36 UTC

There are several such algorithms. The simplest is just counting 1, 2, 3, 4.... You can plug in any whole number and add or subtract one and get the next or previous number in the series.

Would you clarify requirements please, since I don't think that's really what you're asking.

Reply

elfric August 19 2006, 09:04:29 UTC
ok, so I didn't state the idea very well (no, counting up and down is not what I'm after :)

So, what I want is a pseudo-random number generation algorithm (such as that used by rand() or Mersenne Twister). In such an algorithm, you start with a seed number and then use that seed to calculate the next number in the series. Every call to the algorithm after that uses the results from the last call to get the next result. All the algorithms that I know of use bit shifting or some other form of calculation that lose information so that given a number that was just generated, there's no way to calculate what the previous number in that series was. So, what I'm after is an algorithm that doesn't lose information and given any number I can use an algorithm to generate the next number in the series or a reverse of that algorithm to get the PREVIOUS number in that series.

Hopefully that explains a bit better.

Reply

omnifarious August 19 2006, 15:54:30 UTC

That does explain it a lot better.

I think you might be able to use a linear congruential random number generator in this way. Linear congruential random number generators only use multiplicatin and addition modulo 2n, and I think those are reversible. Linear congruential generators are not very good. In particular, their lowest bits tend to move through predictable patterns, but I believe that otherwise they are likely to fit the bill.

Reply


princessgeek August 19 2006, 16:16:19 UTC
PIE!

Reply

elfric August 19 2006, 17:39:47 UTC
mmmmm, PI....

Reply


summersnake August 22 2006, 08:52:49 UTC
That's not much of a random number generator, is it, if you can predict the next number simply by knowing the previous? If only the lottery worked that way (and I knew the seed!)

Reply

elfric August 22 2006, 17:32:30 UTC
Did I say anything about a random number generator? :) I want a numeric series generator that is pseudo-random. Predictability is exactly what I want though (luckily, this isn't for encryption :) )

Reply

summersnake August 22 2006, 17:33:46 UTC
Ahh.... what you want is a nonobvious sequence generator :-)

Reply


Leave a comment

Up