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?
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.
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.
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.
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!)
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 :) )
Comments 8
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
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
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
Reply
Reply
Reply
Reply
Reply
Leave a comment